From 7057e839210e5e3f6aa4c527ac16edac9004f235 Mon Sep 17 00:00:00 2001 From: Dariusz Szut Date: Wed, 21 Sep 2016 15:01:34 +0200 Subject: [PATCH 1/3] EZS-900: Editing translated version sets language to english --- .../js/views/popups/ezs-versionspopupview.js | 35 ++++-- .../js/views/services/ezs-browserviewservice.js | 7 +- .../ezs-dynamiclandingpageeditorviewservice.js | 7 +- .../plugins/ezs-contentcreateredirectplugin.js | 56 ++++++--- .../plugins/ezs-studionavigationhubplugin.js | 125 ++++++++++++++++----- 5 files changed, 171 insertions(+), 59 deletions(-) diff --git a/Resources/public/js/views/popups/ezs-versionspopupview.js b/Resources/public/js/views/popups/ezs-versionspopupview.js index 15aee93..7ad957b 100644 --- a/Resources/public/js/views/popups/ezs-versionspopupview.js +++ b/Resources/public/js/views/popups/ezs-versionspopupview.js @@ -43,7 +43,7 @@ YUI.add('ezs-versionspopupview', function (Y) { SELECTOR_COUNT = '.ezs-popupview--versions__header__headline__count', SELECTOR_CONTENT_TITLE = '.ezs-popupview--versions__header__info__content-title', SELECTOR_CONTENT_TYPE = '.ezs-popupview--versions__header__info__content-type', - STATUS_PUBLISHED = 'published', + STATUS_PUBLISHED = 1, SORT_ASC = 'ASC', SORT_DESC = 'DESC'; @@ -131,14 +131,19 @@ YUI.add('ezs-versionspopupview', function (Y) { created: [] }, dateFormat = this.get('dateFormat'), + parseVersion = function (model) { var versionData = model.toJSON(), date = new Date(this._getJsTimestamp(versionData.created)); - if (versionData.status.toLowerCase() === STATUS_PUBLISHED) { + if (versionData.status === STATUS_PUBLISHED) { this._set('contentTitle', versionData.name); } + if (!versionData.language) { + versionData.language = this.get('missingLanguageText').replace('{language}', versionData.expectedLanguage); + } + versionsData.statuses.push({ versionId: versionData.id, value: versionData.status @@ -675,15 +680,17 @@ YUI.add('ezs-versionspopupview', function (Y) { * @attribute statusesText * @type Object * @default { - * ARCHIVED: 'Archived', - * PUBLISHED: 'Published' + * 0: 'Draft', + * 1: 'Published', + * 3: 'Archived' * } * @writeOnce 'initOnly' */ statusesText: { value: { - ARCHIVED: 'Archived', - PUBLISHED: 'Published' + 0: 'Draft', + 1: 'Published', + 3: 'Archived' }, writeOnce: 'initOnly' }, @@ -845,7 +852,21 @@ YUI.add('ezs-versionspopupview', function (Y) { dateFormat: { value: '%F %R', writeOnce: 'initOnly' - } + }, + + /** + * The missing language information text. + * The language - {language}, placeholder will be replaced with expected language. + * + * @attribute missingLanguageText + * @type String + * @default 'Missing {language} translation' + * @writeOnce 'initOnly' + */ + missingLanguageText: { + value: 'Missing {language} translation', + writeOnce: 'initOnly' + }, } }); }); diff --git a/Resources/public/js/views/services/ezs-browserviewservice.js b/Resources/public/js/views/services/ezs-browserviewservice.js index 287d7dd..6019f47 100644 --- a/Resources/public/js/views/services/ezs-browserviewservice.js +++ b/Resources/public/js/views/services/ezs-browserviewservice.js @@ -378,7 +378,7 @@ YUI.add('ezs-browserviewservice', function (Y) { contentService = capi.getContentService(), loadOptions = { api: capi, - languageCode: content.mainLanguageCode + languageCode: this._getActiveSiteaccessDefaultLanguage() }, getContentUser = function (resolve, reject) { userService.loadUser(content.Owner._href, function (error, response) { @@ -432,6 +432,7 @@ YUI.add('ezs-browserviewservice', function (Y) { try { Y.io(contentVersionsUrl, { + data: {siteaccessName: app.get('studioActiveSiteaccess')}, on: { success: function (id, xhr) { resolve(JSON.parse(xhr.response)); @@ -547,10 +548,6 @@ YUI.add('ezs-browserviewservice', function (Y) { this._showLoadingScreen(); - if (this.get('version').get('id') === versionData._href) { - return true; - } - return new Y.Promise(Y.bind(function (resolve, reject) { this._loadVersion(versionData._href, resolve, reject); }, this)); diff --git a/Resources/public/js/views/services/ezs-dynamiclandingpageeditorviewservice.js b/Resources/public/js/views/services/ezs-dynamiclandingpageeditorviewservice.js index 67f6c38..e92d3f6 100644 --- a/Resources/public/js/views/services/ezs-dynamiclandingpageeditorviewservice.js +++ b/Resources/public/js/views/services/ezs-dynamiclandingpageeditorviewservice.js @@ -128,7 +128,9 @@ YUI.add('ezs-dynamiclandingpageeditorviewservice', function (Y) { */ _getScheduleBlockContentNames: function () { var slotContentPromises = [], - pageData = JSON.parse(this.get('version').get('fields').page.fieldValue).page; + version = this.get('version'), + pageData = JSON.parse(version.get('fields').page.fieldValue).page, + pageTitle = version.get('names')[this.get('languageCode')]; this._showLoadingScreen(); @@ -144,7 +146,8 @@ YUI.add('ezs-dynamiclandingpageeditorviewservice', function (Y) { }, this)); }, this)); - pageData.title = this.get('content').get('name'); + + pageData.title = !!pageTitle ? pageTitle : this.get('content').get('name'); this.set('landingPageData', pageData); this._updatePageData(this._prepareUIConfig()); diff --git a/Resources/public/js/views/services/plugins/ezs-contentcreateredirectplugin.js b/Resources/public/js/views/services/plugins/ezs-contentcreateredirectplugin.js index d66f634..49da13a 100644 --- a/Resources/public/js/views/services/plugins/ezs-contentcreateredirectplugin.js +++ b/Resources/public/js/views/services/plugins/ezs-contentcreateredirectplugin.js @@ -60,22 +60,35 @@ YUI.add('ezs-contentcreateredirectplugin', function (Y) { var host = this.get('host'), app = host.get('app'), capi = host.get('capi'), - contentService = capi.getContentService(), contentLoadPromise, identifierPrefix = 'publish-landing-page-', getUrlAliasRefList = function (content) { - return new Y.Promise(function (resolve, reject) { - contentService.listLocationAliases(content.MainLocation._href, false, function (error, response) { - try { - resolve(response.document.UrlAliasRefList); - } catch (e) { - reject({ - message: 'Cannot list location aliases for location: ' + content.MainLocation._href, - identifier: identifierPrefix + 'load-location-aliases' - }, e); - } - }); - }); + return new Y.Promise(Y.bind(function (resolve, reject) { + var errorConfig = { + message: 'Cannot list location aliases for location: ' + content.MainLocation._href, + identifier: identifierPrefix + 'load-location-aliases' + }; + + try { + Y.io(this.get('urlAliasRefListUrl').replace('{location}', content.MainLocation._href), { + data: { + custom: false, + siteaccessName: app.get('studioActiveSiteaccess') + }, + headers: {Accept: 'application/vnd.ez.api.UrlAliasRefList+json'}, + on: { + success: function (id, xhr) { + resolve(JSON.parse(xhr.response).UrlAliasRefList); + }, + failure: function (id, xhr) { + reject(errorConfig, xhr); + } + } + }); + } catch (e) { + reject(errorConfig, e); + } + }, this)); }, getUrlAlias = function (refList) { return new Y.Promise(Y.bind(function (resolve, reject) { @@ -136,7 +149,7 @@ YUI.add('ezs-contentcreateredirectplugin', function (Y) { } }); }) - .then(getUrlAliasRefList) + .then(Y.bind(getUrlAliasRefList, this)) .then(Y.bind(getUrlAlias, this)) .then(redirectUser) .catch(Y.bind(this._handleError, host)); @@ -159,6 +172,21 @@ YUI.add('ezs-contentcreateredirectplugin', function (Y) { value: 'studio/urlalias/', writeOnce: 'initOnly' }, + + /** + * The AJAX request url to get url alias ref list + * The URL string contains a placeholder, where location's ID is placed ({location}). + * + * @attribute urlAliasRefListUrl + * @default '{location}/urlaliases' + * @type String + * @writeOnce 'initOnly' + */ + urlAliasRefListUrl: { + value: '{location}/urlaliases', + writeOnce: 'initOnly' + } + } }); diff --git a/Resources/public/js/views/services/plugins/ezs-studionavigationhubplugin.js b/Resources/public/js/views/services/plugins/ezs-studionavigationhubplugin.js index e8060bc..e273990 100644 --- a/Resources/public/js/views/services/plugins/ezs-studionavigationhubplugin.js +++ b/Resources/public/js/views/services/plugins/ezs-studionavigationhubplugin.js @@ -266,52 +266,101 @@ YUI.add('ezs-studionavigationhubplugin', function (Y) { * @protected */ _loadLocationAlias: function (locationId, callback) { - var host = this.get('host'), - app = host.get('app'), - contentService = host.get('capi').getContentService(); + var host = this.get('host'); - contentService.listLocationAliases(locationId, false, Y.bind(function (error, response) { - var locationAlias, - locationRemoteId, - activeSiteaccess = app.get('studioActiveSiteaccess'); - - if (error) { + this._getUrlAliasRefList(locationId) + .then(Y.bind(this._getUrlAlias, this)) + .then(callback) + .catch(function (errorConfig) { host.fire('notify', { notification: { - text: 'Cannot list location aliases for location: ' + locationId, - identifier: 'load-location-aliases', + text: errorConfig.message, + identifier: errorConfig.identifier, state: 'error', timeout: 0 } }); + }); + }, + + /** + * Gets the url Alias Ref List + * + * @method _getUrlAliasRefList + * @param locationId {String} the location id + * @protected + */ + _getUrlAliasRefList: function (locationId) { + var app = this.get('host').get('app'); + + return new Y.Promise(Y.bind(function (resolve, reject) { + var errorConfig = { + message: 'Cannot list location aliases for location: ' + locationId, + identifier: 'load-location-aliases' + }; + + try { + Y.io(this.get('urlAliasRefListUrl').replace('{location}', locationId), { + data: { + custom: false, + siteaccessName: app.get('studioActiveSiteaccess') + }, + headers: {Accept: 'application/vnd.ez.api.UrlAliasRefList+json'}, + on: { + success: function (id, xhr) { + resolve(JSON.parse(xhr.response).UrlAliasRefList); + }, + failure: function (id, xhr) { + reject(errorConfig, xhr); + } + } + }); + } catch (e) { + reject(errorConfig, e); } + }, this)); + }, + + /** + * Gets the url Alias + * + * @method _getUrlAlias + * @param refList {Array} the url alias ref list + * @protected + */ + _getUrlAlias: function (refList) { + var app = this.get('host').get('app'); + + return new Y.Promise(Y.bind(function (resolve, reject) { + var errorConfig = { + message: 'Cannot load URL alias for location', + identifier: 'load-url-alias' + }, + activeSiteaccess = app.get('studioActiveSiteaccess'), + locationAlias = refList.UrlAlias[0]._href.split('/'), + locationRemoteId = locationAlias[locationAlias.length - 1]; activeSiteaccess = activeSiteaccess || Object.keys(app.get('config.studioSiteaccesses'))[0]; - locationAlias = response.document.UrlAliasRefList.UrlAlias[0]._href.split('/'); - locationRemoteId = locationAlias[locationAlias.length - 1]; if (activeSiteaccess !== app.get('studioActiveSiteaccess')) { app.set('studioActiveSiteaccess', activeSiteaccess); } - Y.io(app.get('apiRoot') + this.get('urlAliasUrl') + locationRemoteId, { - headers: {'X-Siteaccess': activeSiteaccess}, - on: { - success: function (id, xhr) { - callback((JSON.parse(xhr.response)).path); - }, - failure: function (id, xhr) { - host.fire('notify', { - notification: { - text: 'Cannot load URL alias for location alias: ' + locationRemoteId, - identifier: 'load-location-alias', - state: 'error', - timeout: 0 - } - }); + try { + Y.io(app.get('apiRoot') + this.get('urlAliasUrl') + locationRemoteId, { + headers: {'X-Siteaccess': activeSiteaccess}, + on: { + success: function (id, xhr) { + resolve((JSON.parse(xhr.response)).path); + }, + failure: function (id, xhr) { + reject(errorConfig, xhr); + } } - } - }); + }); + } catch (e) { + reject(errorConfig, e); + } }, this)); }, @@ -421,7 +470,21 @@ YUI.add('ezs-studionavigationhubplugin', function (Y) { * @attribute selectedLocationId * @type String */ - selectedLocationId: {} + selectedLocationId: {}, + + /** + * The AJAX request url to get url alias ref list + * The URL string contains a placeholder, where location's ID is placed ({location}). + * + * @attribute urlAliasRefListUrl + * @default '{location}/urlaliases' + * @type String + * @writeOnce 'initOnly' + */ + urlAliasRefListUrl: { + value: '{location}/urlaliases', + writeOnce: 'initOnly' + } } }); From 1e92c9d6b7c37939c16ad1b6aed846767ffeb716 Mon Sep 17 00:00:00 2001 From: Nattfarinn Date: Thu, 22 Sep 2016 11:22:48 +0200 Subject: [PATCH 2/3] EZS-900: Expose siteaccess aware listLocationAliases REST endpoint --- Controller/StudioUIController.php | 44 ++++++++++++++++++++++++++++++++++++++- Resources/config/routing.yml | 9 ++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Controller/StudioUIController.php b/Controller/StudioUIController.php index 8d3c2cf..4412723 100644 --- a/Controller/StudioUIController.php +++ b/Controller/StudioUIController.php @@ -13,6 +13,7 @@ use eZ\Publish\API\Repository\UserService; use eZ\Publish\API\Repository\Values\Content\URLAlias; use eZ\Publish\API\Repository\Values\Content\VersionInfo; +use eZ\Publish\Core\REST\Server\Values; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; use eZ\Publish\Core\Base\Exceptions\NotFoundException; @@ -213,7 +214,10 @@ public function siteaccessesAction(Request $request) /** * Returns the URL alias with the given ID. * - * @param $urlAliasId + * @param int $urlAliasId + * @param Request $request + * + * @return JsonResponse */ public function loadURLAlias($urlAliasId, Request $request) { @@ -266,6 +270,44 @@ public function loadURLAlias($urlAliasId, Request $request) } /** + * Returns the list of URL aliases for a location (siteaccess aware) + * + * @param string $locationPath + * @param Request $request + * + * @return \eZ\Publish\Core\REST\Server\Values\URLAliasRefList + */ + public function listLocationURLAliases($locationPath, Request $request) + { + $locationPathParts = explode('/', $locationPath); + + $location = $this->locationService->loadLocation( + array_pop($locationPathParts) + ); + + $custom = $request->query->has('custom') && $request->query->get('custom') === 'false' ? false : true; + $siteaccessName = $request->query->has('siteaccessName') + ? $request->query->get('siteaccessName') + : $this->container->get('ezpublish.siteaccess')->name; + + $languages = $this->getConfigResolver()->getParameter( + 'languages', + 'ezsettings', + $siteaccessName + ); + + $preferedLanguage = array_shift($languages); + + $aliases = $this->urlAliasService->listLocationAliases($location, $custom, $preferedLanguage); + + if (empty($aliases)) { + $aliases = $this->urlAliasService->listLocationAliases($location, $custom); + } + + return new Values\URLAliasRefList($aliases, $request->getPathInfo()); + } + + /** * Removes a siteaccess string from the url. * * @param string $url diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index 4f7796e..3a1a73b 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -24,3 +24,12 @@ studioui_layout_preview: _controller: FrameworkBundle:Template:template template: eZStudioUIBundle:Static:layout.html.twig methods: [GET] + +# Override: @EzPublishRestBundle/Resources/config/routing.yml:ezpublish_rest_listLocationURLAliases +ezpublish_rest_listLocationURLAliases: + path: /api/ezp/v2/content/locations/{locationPath}/urlaliases + defaults: + _controller: ez_studioui.studio:listLocationURLAliases + methods: [GET] + requirements: + locationPath: "[0-9/]+" From 0b735a06588342b1a7163771f50238a88f214652 Mon Sep 17 00:00:00 2001 From: Nattfarinn Date: Thu, 22 Sep 2016 12:29:55 +0200 Subject: [PATCH 3/3] EZS-900: Limit version list only to ones that belong to main siteaccess language --- Controller/StudioUIController.php | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/Controller/StudioUIController.php b/Controller/StudioUIController.php index 4412723..bbc3521 100644 --- a/Controller/StudioUIController.php +++ b/Controller/StudioUIController.php @@ -60,19 +60,38 @@ public function contentVersions(Request $request, $contentId) throw new BadRequestHttpException('The request is not AJAX request'); } + $siteaccessName = $request->query->has('siteaccessName') + ? $request->query->get('siteaccessName') + : $this->container->get('ezpublish.siteaccess')->name; + + $languages = $this->getConfigResolver()->getParameter( + 'languages', + 'ezsettings', + $siteaccessName + ); + + $language = array_shift($languages); + $contentInfo = $this->contentService->loadContentInfo($contentId); $rawVersions = array_reverse($this->contentService->loadVersions($contentInfo)); $authors = []; $versions = []; - $statusNames = [ - VersionInfo::STATUS_DRAFT => 'Draft', - VersionInfo::STATUS_PUBLISHED => 'Published', - VersionInfo::STATUS_ARCHIVED => 'Archived', - ]; - + /** @var VersionInfo $version */ foreach ($rawVersions as $version) { + $displayLanguage = $language; + + if ($version->initialLanguageCode != $language) { + if ($version->status === VersionInfo::STATUS_PUBLISHED) { + if (!in_array($language, $version->languageCodes)) { + $displayLanguage = false; + } + } else { + continue; + } + } + $ownerId = $version->creatorId; if (!isset($authors[$ownerId])) { @@ -91,8 +110,9 @@ public function contentVersions(Request $request, $contentId) 'name' => $version->getName(), 'created' => $version->creationDate->getTimestamp(), 'author' => $authors[$ownerId], - 'status' => $statusNames[$version->status], - 'language' => $version->initialLanguageCode, + 'status' => $version->status, + 'language' => $displayLanguage, + 'expectedLanguage' => $language, ]; } @@ -270,7 +290,7 @@ public function loadURLAlias($urlAliasId, Request $request) } /** - * Returns the list of URL aliases for a location (siteaccess aware) + * Returns the list of URL aliases for a location (siteaccess aware). * * @param string $locationPath * @param Request $request