studio chutier is updating when documents added or removed, also added remove link in document list
This commit is contained in:
@@ -1,23 +1,33 @@
|
||||
(function ($, Drupal) {
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
|
||||
var settings = drupalSettings.edlp_studio;
|
||||
|
||||
function init(){
|
||||
console.log('Studio Init');
|
||||
initEvents();
|
||||
initAjax();
|
||||
initAjaxChutier();
|
||||
};
|
||||
|
||||
function initEvents(){
|
||||
$('body').on('new-audio-cartel-loaded', initAjax);
|
||||
$('body')
|
||||
.on('new-audio-cartel-loaded', initAjaxChutier)
|
||||
.on('new-content-ajax-loaded', initAjaxChutier);
|
||||
};
|
||||
|
||||
function initAjax(){
|
||||
|
||||
// ___ _ _ _ _ _ _ _ _ _
|
||||
// / __| |_ _ _| |_(_)___ _ _ | \| |___ __| |___ | | (_)_ _ | |__ ___
|
||||
// | (__| ' \ || | _| / -_) '_| | .` / _ \/ _` / -_) | |__| | ' \| / /(_-<
|
||||
// \___|_||_\_,_|\__|_\___|_| |_|\_\___/\__,_\___| |____|_|_||_|_\_\/__/
|
||||
|
||||
function initAjaxChutier(){
|
||||
console.log('studio initAjax chutier');
|
||||
$('.chutier-ajax-link:not(.ajax-enabled)')
|
||||
.addClass('ajax-enabled')
|
||||
.on('click', onClickAjaxLink);
|
||||
.on('click', onClickChutierAjaxLink);
|
||||
};
|
||||
|
||||
function onClickAjaxLink(e){
|
||||
function onClickChutierAjaxLink(e){
|
||||
console.log('studio onClickAjaxLink chutier');
|
||||
e.preventDefault();
|
||||
addRemoveToChutier($(this));
|
||||
@@ -47,7 +57,8 @@
|
||||
'target_id':$link.attr('target_id'),
|
||||
});
|
||||
$link.replaceWith(data.new_link);
|
||||
initAjax();
|
||||
initAjaxChutier();
|
||||
updateStudioChutier();
|
||||
// TODO: reload Studio chutier_ui's documents list
|
||||
};
|
||||
|
||||
@@ -55,5 +66,41 @@
|
||||
console.warn('add to chuttier load failed : '+error, jqxhr.responseText);
|
||||
};
|
||||
|
||||
|
||||
// ___ _ _ _ _
|
||||
// / __| |_ _ _ __| (_)___ ___ _ _(_)
|
||||
// \__ \ _| || / _` | / _ \___| || | |
|
||||
// |___/\__|\_,_\__,_|_\___/ \_,_|_|
|
||||
// this seems dirty
|
||||
function updateStudioChutier(){
|
||||
$studioChutier = $('#studio-ui .chutier_ui');
|
||||
if($studioChutier.length){
|
||||
var ajax_path = settings.chutier_ui_ajax;
|
||||
var path = window.location.origin + drupalSettings.path.baseUrl + ajax_path;
|
||||
$studioChutier.addClass('loading');
|
||||
$.getJSON(path, {})
|
||||
.done(function(data){
|
||||
onLoadedChutier($studioChutier, data);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error){
|
||||
onLoadChutierError(jqxhr, textStatus, error, $studioChutier);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function onLoadedChutier($studioChutier, data){
|
||||
$studioChutier.replaceWith(data.rendered);
|
||||
initAjaxChutier();
|
||||
$('body').trigger({
|
||||
'type':'on-studio-chutier-updated'
|
||||
});
|
||||
}
|
||||
|
||||
function onLoadChutierError(jqxhr, textStatus, error, $studioChutier){
|
||||
console.warn('Chutier load failed', jqxhr.responseText);
|
||||
$studioChutier.removeClass('loading');
|
||||
|
||||
}
|
||||
|
||||
init();
|
||||
})(jQuery, Drupal);
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
|
||||
@@ -30,9 +30,10 @@ function edlp_studio_help($route_name, RouteMatchInterface $route_match) {
|
||||
*/
|
||||
function edlp_studio_page_attachments(array &$attachments) {
|
||||
$attachments['#attached']['library'][] = 'edlp_studio/edlp_studio-library';
|
||||
$url = Url::fromRoute('edlp_studio.studio_chutier_ui_ajax', [], ['absolute' => TRUE]);
|
||||
$attachments['#attached']['drupalSettings']['edlp_studio']['chutier_ui_ajax'] = $url->getInternalPath();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
@@ -45,6 +46,7 @@ function edlp_studio_theme($existing, $type, $theme, $path) {
|
||||
'variables' => array(
|
||||
'title' => t('Chutier'),
|
||||
'document_nodes' => array(),
|
||||
'uid' => null,
|
||||
),
|
||||
),
|
||||
'edlp_composition_ui' => array(
|
||||
@@ -64,8 +66,6 @@ function edlp_studio_theme($existing, $type, $theme, $path) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* hook_entity_extra_field_info()
|
||||
*
|
||||
@@ -82,7 +82,6 @@ function edlp_studio_entity_extra_field_info(){
|
||||
return $extra;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_ENTITY_TYPE_view().
|
||||
* @see https://www.amazeelabs.com/en/render-menu-tree-custom-code-drupal-8
|
||||
|
||||
@@ -30,3 +30,11 @@ edlp_studio.studio_ui_ajax:
|
||||
_title: 'Studio User Interface'
|
||||
requirements:
|
||||
_permission: 'use chutier'
|
||||
|
||||
edlp_studio.studio_chutier_ui_ajax:
|
||||
path: '/edlp/studio/chutier-ui/ajax'
|
||||
defaults:
|
||||
_controller: '\Drupal\edlp_studio\Controller\StudioUIController::StudioChutierUIJson'
|
||||
_title: 'Chutier of Studio User Interface'
|
||||
requirements:
|
||||
_permission: 'use chutier'
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
use \Drupal\Core\Url;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
use Drupal\edlp_studio\Entity\Chutier;
|
||||
|
||||
function template_preprocess_edlp_chutier_ui(&$vars){
|
||||
// dpm($vars);
|
||||
// $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
|
||||
@@ -34,23 +36,44 @@ function template_preprocess_edlp_chutier_ui(&$vars){
|
||||
foreach ($node->get('field_entrees')->getValue() as $key => $term) {
|
||||
$entrees .= '<span class="entree" tid="'.$term['target_id'].'"></span>';
|
||||
}
|
||||
//
|
||||
// get the remove url (obviously as we are in chutier all contents actions are remove ;)
|
||||
$remove_url = Chutier::getActionsUrl($node->id(), $vars['uid']);
|
||||
|
||||
// build the link
|
||||
$vars['documents']['#items'][] = array(
|
||||
'#prefix' => '<div class="entrees">'.$entrees.'</div>',
|
||||
'#title' => $trunc_title,
|
||||
'#type' => 'link',
|
||||
'#url' => $url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $url->getInternalPath(),
|
||||
'audio_url' => $son_url,
|
||||
'nid' => $node->id(),
|
||||
// 'tid' => $entrees[mt_rand(0, count($entrees) - 1)],
|
||||
// 'entries_size' => count($entrees),
|
||||
'class' => $classes,
|
||||
'title'=>$title,
|
||||
)
|
||||
)
|
||||
'#type' => 'container',
|
||||
'entrees' => array(
|
||||
'#type' => 'container',
|
||||
'#attributes'=>['class'=>['entrees']],
|
||||
'#markup'=>$entrees,
|
||||
),
|
||||
'link'=>array(
|
||||
'#title' => $trunc_title,
|
||||
'#type' => 'link',
|
||||
'#url' => $url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $url->getInternalPath(),
|
||||
'audio_url' => $son_url,
|
||||
'nid' => $node->id(),
|
||||
// 'tid' => $entrees[mt_rand(0, count($entrees) - 1)],
|
||||
// 'entries_size' => count($entrees),
|
||||
'class' => $classes,
|
||||
'title'=>$title,
|
||||
),
|
||||
),
|
||||
),
|
||||
'remove_link' => array(
|
||||
'#title' => t("Chutier."),
|
||||
'#type' => 'link',
|
||||
'#url' => $remove_url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $remove_url->getInternalPath()
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class StudioUIController extends ControllerBase {
|
||||
* Return renderable array.
|
||||
*/
|
||||
public function StudioUIJson() {
|
||||
$renderable = $this->buildUI();
|
||||
$renderable = $this->buildStudioUI();
|
||||
$rendered = render($renderable);
|
||||
|
||||
// JSON
|
||||
@@ -68,11 +68,27 @@ class StudioUIController extends ControllerBase {
|
||||
|
||||
}
|
||||
|
||||
public function buildUI(){
|
||||
// get current user
|
||||
// done by DependencyInjection of AccountInterface
|
||||
// dpm($this->user->id());
|
||||
public function StudioChutierUIJson(){
|
||||
$renderable = $this->buildChutierUI();
|
||||
$rendered = render($renderable);
|
||||
|
||||
// JSON
|
||||
$response = new JsonResponse();
|
||||
$response->setData([
|
||||
'rendered'=> $rendered,
|
||||
]);
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function buildStudioUI(){
|
||||
return [
|
||||
'#theme' => 'edlp_studio_ui',
|
||||
'#chutier_ui' => $this->buildChutierUI(),
|
||||
'#composition_ui' => $this->buildCompostionUI(),
|
||||
];
|
||||
}
|
||||
|
||||
private function buildChutierUI(){
|
||||
// get his docs in chutier
|
||||
$documents_nids = Chutier::getUserChutiersContents($this->user->id());
|
||||
// dpm($documents_nids);
|
||||
@@ -84,8 +100,13 @@ class StudioUIController extends ControllerBase {
|
||||
"#theme"=>'edlp_chutier_ui',
|
||||
'#title' => t('Chutier'),
|
||||
"#document_nodes" => $documents,
|
||||
'#uid' => $this->user->id(),
|
||||
);
|
||||
|
||||
return $chutier_ui;
|
||||
}
|
||||
|
||||
private function buildCompostionUI(){
|
||||
// TODO: get compositions
|
||||
// TODO: add compositions theme, preprocess, twig template to studio module
|
||||
// TODO: build content renderable array
|
||||
@@ -95,13 +116,6 @@ class StudioUIController extends ControllerBase {
|
||||
"#compositions" => array('#markup'=>'TODO : compositions UI'),
|
||||
);
|
||||
|
||||
// TODO: add studio theme, preprocess, twig template to studio module
|
||||
// TODO: build global studio renderable array
|
||||
|
||||
return [
|
||||
'#theme' => 'edlp_studio_ui',
|
||||
'#chutier_ui' => $chutier_ui,
|
||||
'#composition_ui' => $composition_ui,
|
||||
];
|
||||
return $composition_ui;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,5 +102,4 @@ interface ChutierInterface extends ContentEntityInterface, EntityChangedInterfac
|
||||
*/
|
||||
public static function getActionsURL($id, $uid);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user