history nav is now ok

This commit is contained in:
Bachir Soussi Chiadmi
2018-04-03 15:00:13 +02:00
parent f3fc776b71
commit 4e01b68f5b
20 changed files with 810 additions and 554 deletions
@@ -5,6 +5,53 @@
# @Filename: edlp_ajax.module
# @License: GPL-V3
use Drupal\Core\Url;
/**
* Implements hook_page_attachments().
* @param array $attachments
*/
function edlp_ajax_page_attachments(array &$attachments) {
$url = Url::fromRoute('edlp_ajax.entityjson');
$attachments['#attached']['drupalSettings']['edlp_ajax']['entityjson_path'] = $url->getInternalPath();
// $url = Url::fromRoute('edlp_ajax.urljson');
// $attachments['#attached']['drupalSettings']['edlp_ajax']['urljson_path'] = $url->getInternalPath();
$redirect = false;
$current_path = \Drupal::service('path.current')->getPath();
$is_front = \Drupal::service('path.matcher')->isFrontPage();
// do not redirect if note node, term, or custom routing
if(preg_match('/^\/?node\/\d+/', $current_path)
|| preg_match('/^\/?taxonomy\/term\/\d+/', $current_path)
|| preg_match('/^\/?productions/', $current_path)
|| preg_match('/^\/?agenda/', $current_path)
|| preg_match('/^\/?studio/', $current_path)){
// TODO: search url
$redirect = true;
}
$js_str = "var edlp = {\n
sys_path:'".$current_path."',\n
is_front:".($is_front ? 'true':'false').",\n
redirect:".($redirect ? 'true':'false').",\n
};";
$attachments['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'script',
'#value' => $js_str,
'#weight' => -999,
'#group' => 'edlp'
],
// A key, to make it possible to recognize this HTML element when altering.
'edlp',
];
}
/**
* Implements hook_theme().
*/
@@ -6,20 +6,14 @@
# @Last modified time: 20-12-2017
# @License: GPL-V3
edlp_ajax.node:
path: '/edlp/ajax/{entity_type}/{id}/{viewmode}'
defaults:
_controller: '\Drupal\edlp_ajax\Controller\EdlpAjaxController::entity'
_title: 'EdlpAjax'
viewmode: 'default'
requirements:
_permission: 'access content'
edlp_ajax.ajaxnode:
path: '/edlp/ajax/json/{entity_type}/{id}/{viewmode}'
edlp_ajax.entityjson:
path: '/edlp/ajax/entity/json/{entity_type}/{id}/{viewmode}'
defaults:
_controller: '\Drupal\edlp_ajax\Controller\EdlpAjaxController::entityjson'
_title: 'EdlpAjaxJson'
entity_type : null
id: null
viewmode: 'default'
requirements:
_permission: 'access content'
# id: \d+
@@ -3,6 +3,9 @@
namespace Drupal\edlp_ajax\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Url;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -29,18 +32,6 @@ class EdlpAjaxController extends ControllerBase {
}
}
/**
* Display entity as a page.
*
* @return renderable array
*/
public function entity($entity_type, $id, $viewmode) {
$this->entity_type = $entity_type;
$this->id = $id;
$this->viewmode = $viewmode;
return $this->toRenderable();
}
/**
* Get entity as json through ajax.
*
@@ -50,6 +41,7 @@ class EdlpAjaxController extends ControllerBase {
$this->entity_type = $entity_type;
$this->id = $id;
$this->viewmode = $viewmode;
$renderable = $this->toRenderable();
$rendered = render($renderable);
@@ -64,17 +56,43 @@ class EdlpAjaxController extends ControllerBase {
$bundle = NULL;
}
$response = new JsonResponse();
$response->setData([
$data = [
'test' => 'hello edlp ajax',
'id' => $this->id,
'view_mode' => $this->viewmode,
'bundle' => $bundle,
'entity_type' => $this->entity_type,
'rendered'=> $rendered,
]);
];
// if content type page (productions) get the menu items
if($bundle == "page"){
$menuLinkManager = \Drupal::service('plugin.manager.menu.link');
$links = $menuLinkManager->loadLinksByRoute('entity.node.canonical', array('node' => $this->id), 'productions');
// dpm($links, 'links');
$menu_parents = array();
foreach ($links as $link) {
$parents = $menuLinkManager->getParentIds($link->getPluginId());
// dpm($parents, 'parents');
foreach ($parents as $parent_id) {
$parent = $menuLinkManager->getInstance(array('id'=>$parent_id));
// dpm($parent, 'parent');
$url = $parent->getUrlObject();
$sys_path = $url->getInternalPath();
// dpm($sys_path);
$menu_parents[] = $sys_path;
}
}
$data['menu_parents'] = $menu_parents;
}
$response = new JsonResponse();
$response->setData($data);
return $response;
// return array(
// '#markup'=>'hello'
// );
}
}
@@ -60,7 +60,7 @@
var _node_pop_up;
// Colors depend on drupalSettings loaded by edlp_corpus.module
var _ecolors = drupalSettings.edlp_corpus.colors;
console.log('Corpus : _ecolors', _ecolors);
//console.log('Corpus : _ecolors', _ecolors);
// Physics
var _attracter,
_repulser_top,
@@ -127,7 +127,7 @@
console.warn('corpus load failed', jqxhr.responseText);
};
function onCorpusLoaded(data){
console.log('corpus loaded : data', data);
//console.log('corpus loaded : data', data);
// console.log('first node', data.nodes[0]);
// buildParticles(data.nodes);
initPhysics();
@@ -188,7 +188,7 @@
// | .` / _ \/ _` / -_|_-<
// |_|\_\___/\__,_\___/__/
function buildNodes(nodes){
console.log("buildNodes", nodes);
//console.log("buildNodes", nodes);
var d;
for (var i in nodes) {
d = i < 1 ? true : false;
@@ -201,12 +201,12 @@
'audio_url':nodes[i].audio_url
});
}
console.log('_nodes',_nodes);
console.log('_articles_nodes',_articles_nodes);
console.log('_no_articles_nodes',_no_articles_nodes);
console.log('_nodes_by_entries', _nodes_by_entries);
//console.log('_nodes',_nodes);
//console.log('_articles_nodes',_articles_nodes);
//console.log('_no_articles_nodes',_no_articles_nodes);
//console.log('_nodes_by_entries', _nodes_by_entries);
console.log('_physics.attractions.length', _physics.attractions.length);
//console.log('_physics.attractions.length', _physics.attractions.length);
};
function Node(i,node,d){
@@ -624,7 +624,7 @@
}
function createNodesRepulsions(){
// how to delete all these attractions before creates new once
console.log('_nodes_centered', _nodes_centered);
//console.log('_nodes_centered', _nodes_centered);
purgeNodesRepulsions();
for (var n = 0; n < _nodes_centered.length; n++) {
for (var q = n+1; q < _nodes_centered.length; q++) {
@@ -767,13 +767,13 @@
return false;
};
function filterArticles(){
console.log('filterArticles');
//console.log('filterArticles');
for (var i = 0; i < _no_articles_nodes.length; i++) {
_no_articles_nodes[i].fade();
}
};
function resetArticlesFilter(){
console.log('resetArticlesFilter');
//console.log('resetArticlesFilter');
for (var i = 0; i < _no_articles_nodes.length; i++) {
_no_articles_nodes[i].unFade();
}
@@ -856,7 +856,7 @@
_nodes_by_nid[e.target_id].chutier_action = e.new_action;
})
.on('search-results-loaded', function(e){
console.log("Edlp Corpus, search-results-loaded",e.results);
//console.log("Edlp Corpus, search-results-loaded",e.results);
// TODO: filter map's nodes
filterSearchResults(e.results);
})
@@ -981,10 +981,12 @@
function startAnime(){
_physics.onUpdate(render);
_physics.play()
$('body').trigger({
'type':'corpus-map-ready',
'playlist':_playlist
});
$('body')
.attr('corpus', 'map-ready')
.trigger({
'type':'corpus-map-ready',
'playlist':_playlist
});
};
init();
@@ -60,7 +60,7 @@
var _node_pop_up;
// Colors depend on drupalSettings loaded by edlp_corpus.module
var _ecolors = drupalSettings.edlp_corpus.colors;
console.log('Corpus : _ecolors', _ecolors);
//console.log('Corpus : _ecolors', _ecolors);
// Physics
var _attracter,
_repulser_top,
@@ -127,7 +127,7 @@
console.warn('corpus load failed', jqxhr.responseText);
};
function onCorpusLoaded(data){
console.log('corpus loaded : data', data);
//console.log('corpus loaded : data', data);
// console.log('first node', data.nodes[0]);
// buildParticles(data.nodes);
initPhysics();
@@ -188,7 +188,7 @@
// | .` / _ \/ _` / -_|_-<
// |_|\_\___/\__,_\___/__/
function buildNodes(nodes){
console.log("buildNodes", nodes);
//console.log("buildNodes", nodes);
var d;
for (var i in nodes) {
d = i < 1 ? true : false;
@@ -201,12 +201,12 @@
'audio_url':nodes[i].audio_url
});
}
console.log('_nodes',_nodes);
console.log('_articles_nodes',_articles_nodes);
console.log('_no_articles_nodes',_no_articles_nodes);
console.log('_nodes_by_entries', _nodes_by_entries);
//console.log('_nodes',_nodes);
//console.log('_articles_nodes',_articles_nodes);
//console.log('_no_articles_nodes',_no_articles_nodes);
//console.log('_nodes_by_entries', _nodes_by_entries);
console.log('_physics.attractions.length', _physics.attractions.length);
//console.log('_physics.attractions.length', _physics.attractions.length);
};
function Node(i,node,d){
@@ -624,7 +624,7 @@
}
function createNodesRepulsions(){
// how to delete all these attractions before creates new once
console.log('_nodes_centered', _nodes_centered);
//console.log('_nodes_centered', _nodes_centered);
purgeNodesRepulsions();
for (var n = 0; n < _nodes_centered.length; n++) {
for (var q = n+1; q < _nodes_centered.length; q++) {
@@ -767,13 +767,13 @@
return false;
};
function filterArticles(){
console.log('filterArticles');
//console.log('filterArticles');
for (var i = 0; i < _no_articles_nodes.length; i++) {
_no_articles_nodes[i].fade();
}
};
function resetArticlesFilter(){
console.log('resetArticlesFilter');
//console.log('resetArticlesFilter');
for (var i = 0; i < _no_articles_nodes.length; i++) {
_no_articles_nodes[i].unFade();
}
@@ -856,7 +856,7 @@
_nodes_by_nid[e.target_id].chutier_action = e.new_action;
})
.on('search-results-loaded', function(e){
console.log("Edlp Corpus, search-results-loaded",e.results);
//console.log("Edlp Corpus, search-results-loaded",e.results);
// TODO: filter map's nodes
filterSearchResults(e.results);
})
@@ -981,10 +981,12 @@
function startAnime(){
_physics.onUpdate(render);
_physics.play()
$('body').trigger({
'type':'corpus-map-ready',
'playlist':_playlist
});
$('body')
.attr('corpus', 'map-ready')
.trigger({
'type':'corpus-map-ready',
'playlist':_playlist
});
};
init();
@@ -49,6 +49,7 @@ class BlockEntrees extends BlockBase {
'attributes' => array(
'class' => ['term-'.$tid, 'term-link'],
'tid'=>$tid,
'selector' => 'entree-term-link-'.$tid,
'data-drupal-link-system-path' => $url->getInternalPath()
)
));
@@ -61,6 +62,7 @@ class BlockEntrees extends BlockBase {
'class' => ['index-link', 'ajax-link'],
'viewmode'=>'index',
'tid'=>$tid,
'selector' => 'entree-index-link-'.$tid,
'data-drupal-link-system-path' => $url->getInternalPath()
)
));
@@ -73,6 +75,7 @@ class BlockEntrees extends BlockBase {
'class' => ['notice-link', 'ajax-link'],
'viewmode'=>'notice',
'tid'=>$tid,
'selector' => 'entree-notice-link-'.$tid,
'data-drupal-link-system-path' => $url->getInternalPath()
)
));
@@ -6,7 +6,7 @@
var _$form;
function init(){
console.log('EdlpSearch Init', settings);
// console.log('EdlpSearch Init', settings);
initEvents();
initAjax();
};
@@ -20,8 +20,8 @@
function initAjax(){
_$form = $('#edlp-search-form:not(.ajax-enabled)');
if(!_$form.length) return false;
console.log('EdlpSearch initAjaxForm()');
//console.log('EdlpSearch initAjaxForm()');
_$form = $('#edlp-search-form:not(.ajax-enabled)')
.on('submit', onSubmitForm)
.addClass('ajax-enabled');
@@ -51,7 +51,7 @@
// genres
args.genres = $('input[name="genres"]', this).val();
console.log('EdlpSearch onSubmitForm() : args',args);
//console.log('EdlpSearch onSubmitForm() : args',args);
loadResults(args);
@@ -59,7 +59,7 @@
};
function loadResults(args){
console.log('EdlpSearch loadResults() : args', args);
//console.log('EdlpSearch loadResults() : args', args);
_$form.addClass('ajax-loading');
_$body.addClass('ajax-loading');
$('[theme="edlp_search_results"]', _$container).addClass('ajax-loading');
@@ -273,12 +273,12 @@ class EdlpSearchController extends ControllerBase {
$query->keys($this->keys);
}
// TODO: langues
// langues
if (!empty($this->langues)) {
$query->addCondition('field_langues', $this->langues, "=");
}
// TODO: genres
// genres
if (!empty($this->genres)) {
$query->addCondition('field_genres', $this->genres, "=");
}
@@ -6,7 +6,7 @@
// audio play is handled by edlp_theme
function init(){
console.log('Studio Init');
// console.log('Studio Init');
initEvents();
initStudio();
};
@@ -35,13 +35,13 @@
// | (__| ' \ || | _| / -_) '_| | .` / _ \/ _` / -_) | |__| | ' \| / /(_-<
// \___|_||_\_,_|\__|_\___|_| |_|\_\___/\__,_\___| |____|_|_||_|_\_\/__/
function initAjaxChutierLinks(){
console.log('studio initAjaxChutierLinks');
//console.log('studio initAjaxChutierLinks');
$('.chutier-ajax-link:not(.ajax-enabled)')
.addClass('ajax-enabled')
.on('click', onClickChutierAjaxLink);
};
function onClickChutierAjaxLink(e){
console.log('studio onClickAjaxLink chutier');
//console.log('studio onClickAjaxLink chutier');
e.preventDefault();
addRemoveToChutier($(this));
return false;
@@ -60,7 +60,7 @@
});
};
function onActionToChutierDone($link, data){
console.log('onActionToChutierDone',data);
//console.log('onActionToChutierDone',data);
$('body').trigger({
'type':'chutier-action-done',
'action_done':data.action_done,
@@ -82,7 +82,7 @@
// \___\___/_|_|_| .__/\___/__/_|\__|_\___/_||_/__/
// |_|
function initAjaxCompoLinks(){
console.log('studio initAjaxCompoLinks');
//console.log('studio initAjaxCompoLinks');
$('.new-composition-link:not(.ajax-enabled)')
.on('click', onClickNewCompoLink)
.addClass('ajax-enabled');
@@ -101,7 +101,7 @@
// |_| |_|
function onClickCompoLink(e){
e.preventDefault();
console.log('onClickCompoLink');
//console.log('onClickCompoLink');
openCompo($(this));
return false;
};
@@ -120,7 +120,7 @@
});
};
function onOpenCompoDone(data, $link){
console.log('onActionToCompoDone',data);
//console.log('onActionToCompoDone',data);
$('.composition-link').removeClass('is-active');
$link.removeClass('ajax-loading').addClass('is-active');
if($('.composition', $composer).length){
@@ -163,7 +163,7 @@
};
function onNewCompoFormSubmit(e, $link, $form){
var name = $('input[type="text"]',$form).val();
console.log('onNewCompoFormSubmit', name);
//console.log('onNewCompoFormSubmit', name);
if(name != ''){
$form.addClass('ajax-loading').children('*').attr('disabled', 'disabled');
createNewCompo(name, $link, $form);
@@ -185,7 +185,7 @@
});
};
function onCreateCompoDone(data, $link, $form){
console.log('onActionToCompoDone',data);
//console.log('onActionToCompoDone',data);
var $new_link = $(data.new_link);
var $delete_link = $(data.delete_link);
$link
@@ -225,10 +225,10 @@
});
};
function onDeleteCompoDone(data, $link, $form){
console.log('onDeleteCompoDone',data);
//console.log('onDeleteCompoDone',data);
if(data.status == "ok"){
$link.parents('li').remove();
console.log("$('.composition-link').length", $('.composition-link').length);
//console.log("$('.composition-link').length", $('.composition-link').length);
if($('.composition-link').length){
openCompo($('.composition-link').eq(0));
}else{
@@ -365,7 +365,7 @@
});
}
function onOrderChanged(e, ui){
console.log('onOrderChanged : e', e);
//console.log('onOrderChanged : e', e);
var cid = $(e.target).parents('.composition').attr('cid');
var documents = {};
$('a', e.target).each(function(i) {
@@ -376,10 +376,10 @@
recordCompoList(cid, documents);
};
function recordCompoList(cid, docs){
console.log('recordCompoList '+cid, docs);
//console.log('recordCompoList '+cid, docs);
var ajax_path = _settings.save_compo_ajax_url+'/'+cid;
var path = window.location.origin + Drupal.url(ajax_path);
console.log('path', path);
//console.log('path', path);
$.getJSON(path, {
documents:docs
})
@@ -394,7 +394,7 @@
});
}
function onRecordCompoDone(data){
console.log('onDeleteCompoDone',data);
//console.log('onDeleteCompoDone',data);
if(data.status == "ok"){
}else{
console.warn(data.message);
@@ -25,7 +25,7 @@ edlp_studio.composition_controller_action_ajax:
_permission: 'use chutier'
edlp_studio.studio_ui:
path: '/edlp/studio-ui'
path: '/studio'
defaults:
_controller: '\Drupal\edlp_studio\Controller\StudioUIController::StudioUI'
_title: 'Studio User Interface'
@@ -33,7 +33,7 @@ edlp_studio.studio_ui:
_permission: 'use chutier'
edlp_studio.studio_ui_ajax:
path: '/edlp/studio-ui/ajax'
path: '/studio/ajax'
defaults:
_controller: '\Drupal\edlp_studio\Controller\StudioUIController::StudioUIJson'
_title: 'Studio User Interface'
@@ -41,7 +41,7 @@ edlp_studio.studio_ui_ajax:
_permission: 'use chutier'
edlp_studio.studio_chutier_ui_ajax:
path: '/edlp/studio/chutier-ui/ajax'
path: '/studio/chutier-ui/ajax'
defaults:
_controller: '\Drupal\edlp_studio\Controller\StudioUIController::StudioChutierUIJson'
_title: 'Chutier of Studio User Interface'
@@ -51,7 +51,7 @@ class StudioLinkBlock extends BlockBase implements ContainerFactoryPluginInterf
public function build() {
$build = [];
if($this->user->id()){
$url = Url::fromRoute('edlp_studio.studio_ui', [], ['absolute' => TRUE]);
$url = Url::fromRoute('edlp_studio.studio_ui');
$build['edlp_studio_link_block'] = array(
'#title' => "Studio",
'#type' => 'link',