Skip to content

Commit

Permalink
expose cli fix parent publication
Browse files Browse the repository at this point in the history
  • Loading branch information
aynsix committed May 31, 2024
1 parent 288d490 commit 6c5d37e
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function listPublicationAction(PhraseaApplication $app, Request $request)
{
$exposeName = $request->get('exposeName');
$page = empty($request->get('page')) ? 1 : $request->get('page');
$title = urlencode($request->get('title'));

if ($exposeName == null) {
return $app->json([
Expand Down Expand Up @@ -253,7 +254,8 @@ public function listPublicationAction(PhraseaApplication $app, Request $request)
$exposeClient = $proxyConfig->getClientWithOptions($clientOptions);

try {
$uri = '/publications?flatten=true&order[createdAt]=desc&page=' . $page;
$uri = '/publications?flatten=true&order[createdAt]=desc&page=' . $page . '&title=' . $title;

if ($request->get('mine') && $exposeConfiguration['connection_kind'] === 'password') {
$uri .= '&mine=true';
}
Expand Down Expand Up @@ -307,9 +309,22 @@ public function listPublicationAction(PhraseaApplication $app, Request $request)
$exposeFrontBasePath = \p4string::addEndSlash($exposeConfiguration['expose_front_uri']);

if ($request->get('format') == 'pub-list') {
$publicationsList = [];

foreach ($publications as $key => $publication) {
$publicationsList[$key]['id'] = $basePath . '/' . $publication['id'];
$publicationsList[$key]['text'] = $publication['title'];
}

$pagination = ['more' => false];
if ($nextPage) {
$pagination = ['more' => true];
}

return $app->json([
'publications' => $publications,
'basePath' => $basePath
'publications' => $publicationsList,
'basePath' => $basePath,
'pagination' => $pagination
]);
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"npm-modernizr": "^2.8.3",
"pusher-js": "^8.3.0",
"requirejs": "^2.3.5",
"select2": "^4.1.0-rc.0",
"tinymce": "^4.0.28",
"underscore": "^1.8.3",
"zxcvbn": "^4.4.2"
Expand Down
3 changes: 2 additions & 1 deletion resources/gulp/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ gulp.task('build-vendors', [
'build-jquery-test-paths',
'build-simple-colorpicker',
'build-jquery-datetimepicker',
'build-pusher-js'
'build-pusher-js',
'build-select2'
], function () {
});
8 changes: 8 additions & 0 deletions resources/gulp/components/vendors/select2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var gulp = require('gulp');
var config = require('../../config.js');
var utils = require('../../utils.js');

gulp.task('build-select2', [], function(){
return gulp.src([config.paths.nodes + 'select2/**'])
.pipe(gulp.dest(config.paths.build + 'vendors/select2'));
});
44 changes: 26 additions & 18 deletions templates/web/prod/WorkZone/ExposeEdit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
</div>
<div class="ui-widget">
<label>{{ 'prod:expose:publication:Parent Publication' | trans }}</label>
<div id="publication-list-data" class="ui-widget publication_parent_wrapper ">
<div id="publication-list-data" class="ui-widget publication_parent_wrapper" style="margin-top: 10px;margin-left: 2px;">
{% if publication.parent.id %}
{% set parentId = publication.parent.id %}
{% endif %}
<select id="publication_parent" name="parent" tabindex="-1" aria-hidden="true"
class="publication-field">
<option value="">{{ 'prod:expose:publication:Select a parent publication' | trans }}</option>
<option value="">{{ 'prod:expose:publication:Search a parent publication' | trans }}</option>
{% if publication.parent %}
<option value="/publications/{{ publication.parent.id }}" selected="selected">{{ publication.parent.title }}</option>
{% endif %}
Expand Down Expand Up @@ -222,22 +222,30 @@
$(this).next("div#moreSettingInner").toggleClass('hidden');
});
$.ajax({
type: "GET",
url: `/prod/expose/list-publication/?format=pub-list&exposeName={{ exposeName }}`,
success: function (data) {
publicationParent.empty().html('<option value="">{{ "prod:expose:publication:Select a parent publication" | trans }}</option>');
for (i = 0; i < data.publications.length; i++) {
let selected = '';
if (data.publications[i].id == '{{ parentId }}') {
selected = 'selected="selected"';
}
if (data.publications[i].id !== '{{ publication.id }}') {
publicationParent.append('<option value='+ data.basePath + '/' + data.publications[i].id+' ' + selected +'>'+data.publications[i].title+'</option>');
}
}
}
publicationParent.select2({
ajax: {
url: `/prod/expose/list-publication/`,
data: function (params) {
let exposeName = $('#expose_list').val();
// Query parameters will be ?title=[term]&exposeName=[exposeName]&format=pub-list&page=[page]
return {
title: params.term,
exposeName: exposeName,
format: 'pub-list',
editable: 1,
page: params.page || 1
};
},
processResults: function (data) {
return {
results: data.publications,
pagination: data.pagination
};
},
delay: 250
},
dropdownParent: $('#DIALOG-expose-edit')
});
{% if publication.capabilities.operator %}
Expand Down
64 changes: 37 additions & 27 deletions templates/web/prod/WorkZone/ExposeNew.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
</div>
<div class="ui-widget">
<label>{{ 'prod:expose:publication:Parent Publication' | trans }}</label>
<div id="publication-list-data" class="ui-widget publication_parent_wrapper ">
<select id="publication_parent" name="parent" tabindex="-1" aria-hidden="true"
class="publication-field">
<option value="">{{ 'prod:expose:publication:Select a parent publication' | trans }}</option>
<div id="publication-list-data" class="ui-widget publication_parent_wrapper" style="margin-top: 10px;margin-left: 2px;">
<select id="publication_parent" name="parent">
<option value="">{{ 'prod:expose:publication:Search a parent publication' | trans }}</option>
</select>
</div>
</div>
Expand Down Expand Up @@ -158,6 +157,33 @@
}
$(document).ready(function () {
$("#publication_parent").select2({
ajax: {
url: `/prod/expose/list-publication/`,
data: function (params) {
let exposeName = $('#expose_list').val();
// Query parameters will be ?title=[term]&exposeName=[exposeName]&format=pub-list&page=[page]
return {
title: params.term,
exposeName: exposeName,
format: 'pub-list',
editable: 1,
page: params.page || 1
};
},
processResults: function (data) {
return {
results: data.publications,
pagination: data.pagination
};
},
delay: 250
},
dropdownParent: $('#DIALOG-expose-add')
});
$.datetimepicker.setLocale('{{ app['locale'] }}');
$(".new-use-datepicker").datetimepicker({
Expand Down Expand Up @@ -345,17 +371,6 @@
removeSecurityFieldDialogAdd();
});
/**Selected Parent info **/
$(document).on('change', '#publication_parent', function (e) {
var selectedparent = $(this).children('option:selected');
if (selectedparent.val() !== "") {
$('#parent_info').html('').append('<p>Title : ' + selectedparent.data('title') + '</p><p>Slug: ' + selectedparent.data('slug') + '</p>');
} else {
$('#parent_info').html('');
}
});
$('#DIALOG-expose-add').on('submit', '#publication-json', function (e) {
e.preventDefault();
removeSecurityFieldDialogAdd();
Expand Down Expand Up @@ -436,18 +451,6 @@
$('#DIALOG-expose-add').dialog('close');
});
$.ajax({
type: "GET",
url: `/prod/expose/list-publication/?format=pub-list&exposeName=` + exposeName,
success: function (data) {
$('#DIALOG-expose-add #publication_parent').empty().html('<option value="">Select a parent publication</option>');
var i = 0;
for ( ;i < data.publications.length; i++) {
$('#DIALOG-expose-add select#publication_parent').append('<option value=' + data.basePath + '/' + data.publications[i].id+' >'+data.publications[i].title+'</option>');
}
}
});
$.ajax({
type: "GET",
url: `/prod/expose/list-profile?exposeName=` + exposeName,
Expand Down Expand Up @@ -478,5 +481,12 @@
.publication-block .ui-widget.hide {
display: none;
}
.select2-dropdown {
z-index: 4000;
}
.select2-container {
color: #555;
font-size: 14px;
}
</style>
{% endmacro %}
3 changes: 3 additions & 0 deletions templates/web/prod/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
{% block stylesheet %}
<link type="text/css" rel="stylesheet" href="/assets/production/production{% if not app.debug %}.min{% endif %}.css?v={{ assetFileVersion }}">
<link id="skinCss" type="text/css" rel="stylesheet" href="/assets/production/skin-{{ cssfile }}{% if not app.debug %}.min{% endif %}.css?v={{ assetFileVersion }}">
<link href="/assets/vendors/select2/dist/css/select2.min.css" rel="stylesheet" />

<style title="color_selection" type="text/css">
.diapo.selected,#reorder_box .diapo.selected, #EDIT_ALL .diapo.selected, .list.selected, .list.selected .diapo {
color: {{"#" ~ app['settings'].getUserSetting(app.getAuthenticatedUser(), 'fontcolor-selection', 'FFFFFF')}};
Expand All @@ -85,6 +87,7 @@
<script type="text/javascript" src="/assets/production/commons{% if not app.debug %}.min{% endif %}.js?v={{ assetFileVersion }}"></script>
<script type="text/javascript" src="/assets/production/production{% if not app.debug %}.min{% endif %}.js?v={{ assetFileVersion }}"></script>
<script type="text/javascript" src="/assets/vendors/tinymce/tinymce.min.js"></script>
<script type="text/javascript" src="/assets/vendors/select2/dist/js/select2.min.js"></script>
<script type="text/javascript">
Expand Down

0 comments on commit 6c5d37e

Please sign in to comment.