composition sorting is now saving automaticly
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
(function ($, Drupal, drupalSettings) {
|
(function ($, Drupal, drupalSettings) {
|
||||||
|
|
||||||
var settings = drupalSettings.edlp_studio;
|
var _settings = drupalSettings.edlp_studio;
|
||||||
var composer;
|
var $composer;
|
||||||
|
|
||||||
function init(){
|
function init(){
|
||||||
console.log('Studio Init');
|
console.log('Studio Init');
|
||||||
@@ -99,7 +99,7 @@
|
|||||||
};
|
};
|
||||||
function openCompo($link){
|
function openCompo($link){
|
||||||
var cid = $link.attr('cid');
|
var cid = $link.attr('cid');
|
||||||
var ajax_path = settings.open_compo_ajax_url+'/'+cid;
|
var ajax_path = _settings.open_compo_ajax_url+'/'+cid;
|
||||||
var path = window.location.origin + Drupal.url(ajax_path);
|
var path = window.location.origin + Drupal.url(ajax_path);
|
||||||
$link.addClass('ajax-loading');
|
$link.addClass('ajax-loading');
|
||||||
$composer.addClass('ajax-loading');
|
$composer.addClass('ajax-loading');
|
||||||
@@ -228,7 +228,7 @@
|
|||||||
function updateStudioChutier(){
|
function updateStudioChutier(){
|
||||||
$studioChutier = $('#studio-ui .chutier_ui');
|
$studioChutier = $('#studio-ui .chutier_ui');
|
||||||
if($studioChutier.length){
|
if($studioChutier.length){
|
||||||
var ajax_path = settings.chutier_ui_ajax;
|
var ajax_path = _settings.chutier_ui_ajax;
|
||||||
var path = window.location.origin + drupalSettings.path.baseUrl + ajax_path;
|
var path = window.location.origin + drupalSettings.path.baseUrl + ajax_path;
|
||||||
$studioChutier.addClass('loading');
|
$studioChutier.addClass('loading');
|
||||||
$.getJSON(path, {})
|
$.getJSON(path, {})
|
||||||
@@ -335,19 +335,21 @@
|
|||||||
|
|
||||||
function onOrderChanged(e, ui){
|
function onOrderChanged(e, ui){
|
||||||
console.log('onOrderChanged : e', e);
|
console.log('onOrderChanged : e', e);
|
||||||
// TODO: record the current order through ajax
|
var cid = $(e.target).parents('.composition').attr('cid');
|
||||||
var documents = [];
|
var documents = {};
|
||||||
$('a', e.target).each(function(i) {
|
$('a', e.target).each(function(i) {
|
||||||
// console.log(this);
|
// console.log(this);
|
||||||
documents.push($(this).attr('nid'));
|
documents[i] = $(this).attr('nid');
|
||||||
});
|
});
|
||||||
console.log(documents);
|
// console.log(documents);
|
||||||
// recordCompoList(cid, documents);
|
recordCompoList(cid, documents);
|
||||||
};
|
};
|
||||||
|
|
||||||
function recordCompoList(cid, docs){
|
function recordCompoList(cid, docs){
|
||||||
var ajax_path = 'path';
|
console.log('recordCompoList '+cid, docs);
|
||||||
|
var ajax_path = _settings.save_compo_ajax_url+'/'+cid;
|
||||||
var path = window.location.origin + Drupal.url(ajax_path);
|
var path = window.location.origin + Drupal.url(ajax_path);
|
||||||
|
console.log('path', path);
|
||||||
$.getJSON(path, {
|
$.getJSON(path, {
|
||||||
documents:docs
|
documents:docs
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -30,10 +30,15 @@ function edlp_studio_help($route_name, RouteMatchInterface $route_match) {
|
|||||||
*/
|
*/
|
||||||
function edlp_studio_page_attachments(array &$attachments) {
|
function edlp_studio_page_attachments(array &$attachments) {
|
||||||
$attachments['#attached']['library'][] = 'edlp_studio/edlp_studio-library';
|
$attachments['#attached']['library'][] = 'edlp_studio/edlp_studio-library';
|
||||||
|
// chutier ui
|
||||||
$url = Url::fromRoute('edlp_studio.studio_chutier_ui_ajax', [], ['absolute' => TRUE]);
|
$url = Url::fromRoute('edlp_studio.studio_chutier_ui_ajax', [], ['absolute' => TRUE]);
|
||||||
$attachments['#attached']['drupalSettings']['edlp_studio']['chutier_ui_ajax'] = $url->getInternalPath();
|
$attachments['#attached']['drupalSettings']['edlp_studio']['chutier_ui_ajax'] = $url->getInternalPath();
|
||||||
|
// open compo
|
||||||
$url = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action'=>'open'], ['absolute' => TRUE]);
|
$url = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action'=>'open'], ['absolute' => TRUE]);
|
||||||
$attachments['#attached']['drupalSettings']['edlp_studio']['open_compo_ajax_url'] = $url->getInternalPath();
|
$attachments['#attached']['drupalSettings']['edlp_studio']['open_compo_ajax_url'] = $url->getInternalPath();
|
||||||
|
// save compo
|
||||||
|
$url = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action'=>'save'], ['absolute' => TRUE]);
|
||||||
|
$attachments['#attached']['drupalSettings']['edlp_studio']['save_compo_ajax_url'] = $url->getInternalPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,6 +48,10 @@ function edlp_studio_theme($existing, $type, $theme, $path) {
|
|||||||
// @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
|
// @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
'composition' => array(
|
||||||
|
'file' => 'includes/composition.inc',
|
||||||
|
'render element'=>'elements',
|
||||||
|
),
|
||||||
'edlp_chutier_ui' => array(
|
'edlp_chutier_ui' => array(
|
||||||
'file' => 'includes/edlp_chutier_ui.inc',
|
'file' => 'includes/edlp_chutier_ui.inc',
|
||||||
'variables' => array(
|
'variables' => array(
|
||||||
@@ -78,6 +87,29 @@ function edlp_studio_theme($existing, $type, $theme, $path) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_theme_suggestions_HOOK().
|
||||||
|
*/
|
||||||
|
function edlp_studio_theme_suggestions_composition(array $vars) {
|
||||||
|
// dpm($vars);
|
||||||
|
$suggestions = [];
|
||||||
|
|
||||||
|
/** @var \Drupal\edlp_studio\CompositionInterface $compo */
|
||||||
|
$compo = $vars['elements']['#composition'];
|
||||||
|
//
|
||||||
|
$suggestions[] = 'composition';
|
||||||
|
$suggestions[] = 'composition__' . $compo->id();
|
||||||
|
$suggestions[] = 'composition__' . $vars['elements']['#view_mode'];
|
||||||
|
$suggestions[] = 'composition__' . $compo->id() . '__' . $vars['elements']['#view_mode'];
|
||||||
|
// $suggestions[] = 'taxonomy_term__' . $term->id();
|
||||||
|
|
||||||
|
// dpm($suggestions);
|
||||||
|
return $suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hook_entity_extra_field_info()
|
* hook_entity_extra_field_info()
|
||||||
*
|
*
|
||||||
@@ -151,19 +183,3 @@ function edlp_studio_node_view(array &$build, \Drupal\Core\Entity\EntityInterfac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prepares variables for Composition templates.
|
|
||||||
*
|
|
||||||
* Default template: composition.html.twig.
|
|
||||||
*
|
|
||||||
* @param array $variables
|
|
||||||
* An associative array containing:
|
|
||||||
* - elements: An associative array containing the user information and any
|
|
||||||
* - attributes: HTML attributes for the containing element.
|
|
||||||
*/
|
|
||||||
// function edlp_studio_preprocess_composition(array &$vars) {
|
|
||||||
// dpm($vars);
|
|
||||||
// $vars['test'] = 'test';
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Drupal\Core\Render\Element;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares variables for Composition templates.
|
||||||
|
*
|
||||||
|
* Default template: composition.html.twig.
|
||||||
|
*
|
||||||
|
* @param array $variables
|
||||||
|
* An associative array containing:
|
||||||
|
* - elements: An associative array containing the user information and any
|
||||||
|
* - attributes: HTML attributes for the containing element.
|
||||||
|
*/
|
||||||
|
function template_preprocess_composition(array &$vars) {
|
||||||
|
// dpm($variables);
|
||||||
|
// Fetch Composition Entity Object.
|
||||||
|
/** @var \Drupal\edlp_studio\CompositionInterface $composition */
|
||||||
|
$composition = $vars['elements']['#composition'];
|
||||||
|
|
||||||
|
$vars['view_mode'] = $vars['elements']['#view_mode'];
|
||||||
|
|
||||||
|
// $vars['name'] = $composition->getName();
|
||||||
|
// unset($vars['elements']['name']);
|
||||||
|
|
||||||
|
// $variables['page'] = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term);
|
||||||
|
|
||||||
|
$vars['url'] = $composition->url();
|
||||||
|
|
||||||
|
$vars['attributes']['cid'] = $composition->id();
|
||||||
|
$vars['attributes']['class'] = array('composition');
|
||||||
|
|
||||||
|
// Helpful $content variable for templates.
|
||||||
|
foreach (Element::children($vars['elements']) as $key) {
|
||||||
|
$vars['content'][$key] = $vars['elements'][$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
// dpm($vars);
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ function template_preprocess_edlp_composition_ui(&$vars){
|
|||||||
|
|
||||||
|
|
||||||
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('composition');
|
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('composition');
|
||||||
$vars['composition'] = $view_builder->view($vars['lastcomposition']);
|
$vars['composition'] = $view_builder->view($vars['lastcomposition'], 'studio_ui');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ class CompositionController extends ControllerBase {
|
|||||||
$status = 'ok';
|
$status = 'ok';
|
||||||
$message = 'Hello';
|
$message = 'Hello';
|
||||||
|
|
||||||
|
$response = new JsonResponse();
|
||||||
|
|
||||||
switch($action){
|
switch($action){
|
||||||
case 'create':
|
case 'create':
|
||||||
$name = $request->query->get('new_name');
|
$name = $request->query->get('new_name');
|
||||||
@@ -68,6 +70,15 @@ class CompositionController extends ControllerBase {
|
|||||||
$this->error_message = t("Composition opening needs a cid as url paramater!");
|
$this->error_message = t("Composition opening needs a cid as url paramater!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'save':
|
||||||
|
if($cid){
|
||||||
|
$name = $request->query->get('new_name');
|
||||||
|
$documents = $request->query->get('documents');
|
||||||
|
$this->saveComposition($cid, $name, $documents);
|
||||||
|
}else{
|
||||||
|
$this->error_message = t("Composition saving needs a cid as query paramater!");
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'delete':
|
case 'delete':
|
||||||
if($cid){
|
if($cid){
|
||||||
$this->deleteComposition($cid);
|
$this->deleteComposition($cid);
|
||||||
@@ -75,9 +86,6 @@ class CompositionController extends ControllerBase {
|
|||||||
$this->error_message = t("Composition deletion needs a cid as url paramater!");
|
$this->error_message = t("Composition deletion needs a cid as url paramater!");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// case 'rename':
|
|
||||||
//
|
|
||||||
// break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->error_message){
|
if($this->error_message){
|
||||||
@@ -85,8 +93,6 @@ class CompositionController extends ControllerBase {
|
|||||||
$message = $this->error_message;
|
$message = $this->error_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSON
|
|
||||||
$response = new JsonResponse();
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'action' => $action,
|
'action' => $action,
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
@@ -122,16 +128,19 @@ class CompositionController extends ControllerBase {
|
|||||||
'compo' => $this->rendered_compo,
|
'compo' => $this->rendered_compo,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
// case 'delete':
|
case 'save':
|
||||||
// # code...
|
$data += array(
|
||||||
// break;
|
'name'=>$name,
|
||||||
|
'documents'=>$documents
|
||||||
|
);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$response->setData($data);
|
$response->setData($data);
|
||||||
return $response;
|
return $response;
|
||||||
|
|
||||||
// classic html
|
// // classic html
|
||||||
// return array(
|
// return array(
|
||||||
// '#markup'=>'Status : ' . $status . ' | Message : ' . $message,
|
// '#markup'=>'Status : ' . $status . ' | Message : ' . $message,
|
||||||
// );
|
// );
|
||||||
@@ -158,6 +167,20 @@ class CompositionController extends ControllerBase {
|
|||||||
$this->compo = entity_load('composition', $cid);
|
$this->compo = entity_load('composition', $cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function saveComposition($cid, $name = "", $new_documents = array()){
|
||||||
|
$this->compo = entity_load('composition', $cid);
|
||||||
|
if($name != ""){
|
||||||
|
$this->compo->setName($name);
|
||||||
|
}
|
||||||
|
$documents = array();
|
||||||
|
foreach ($new_documents as $nid) {
|
||||||
|
$documents[] = ['target_id'=>$nid];
|
||||||
|
}
|
||||||
|
$this->compo->set('documents', $documents);
|
||||||
|
$this->compo->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private function deleteComposition($cid){
|
private function deleteComposition($cid){
|
||||||
$this->compo = entity_load('composition', $cid);
|
$this->compo = entity_load('composition', $cid);
|
||||||
$this->compo->delete();
|
$this->compo->delete();
|
||||||
|
|||||||
+2
-4
@@ -15,8 +15,6 @@
|
|||||||
* @ingroup themeable
|
* @ingroup themeable
|
||||||
*/
|
*/
|
||||||
#}
|
#}
|
||||||
<div{{ attributes.addClass('composition') }}>
|
<div{{ attributes }}>
|
||||||
{% if content %}
|
{{ content }}
|
||||||
{{- content -}}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
@@ -8,9 +8,7 @@
|
|||||||
<header>
|
<header>
|
||||||
{{ composer_header }}
|
{{ composer_header }}
|
||||||
</header>
|
</header>
|
||||||
<section class="composition">
|
{{ composition }}
|
||||||
{{ composition }}
|
|
||||||
</section>
|
|
||||||
<section class="actions">
|
<section class="actions">
|
||||||
{{ composer_actions }}
|
{{ composer_actions }}
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
Reference in New Issue
Block a user