From 6f67a5eaffc06748ba8371113efefcbfa9fbc04a Mon Sep 17 00:00:00 2001 From: Du Peng Date: Wed, 20 Apr 2022 16:42:59 +0200 Subject: [PATCH] Fix a bug: back bouton can't return to previously page in projects page (list/new/show/edit) --- CHANGELOG.md | 1 + .../src/javascript/controllers/projects.js | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17e2474c3..47ed8e17d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog Fab-manager +- Fix a bug: back bouton can't return to previously page in projects page (list/new/show/edit) - Fix a security issue: updated async to 2.6.4 to fix [CVE-2021-43138](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-43138) ## v5.3.11 2022 April 15 diff --git a/app/frontend/src/javascript/controllers/projects.js b/app/frontend/src/javascript/controllers/projects.js index 1fc27999b..e1be57f41 100644 --- a/app/frontend/src/javascript/controllers/projects.js +++ b/app/frontend/src/javascript/controllers/projects.js @@ -397,6 +397,20 @@ Application.Controllers.controller('ProjectsController', ['$scope', '$state', 'P return true; }; + /** + * Overlap global function to allow the user to navigate to the previous screen + * If no previous $state were recorded, navigate to the project list page + */ + $scope.backPrevLocation = function (event) { + event.preventDefault(); + event.stopPropagation(); + if ($state.prevState === '' || $state.prevState === 'app.public.projects_list') { + $state.prevState = 'app.public.home'; + return $state.go($state.prevState, {}); + } + window.history.back(); + }; + /* PRIVATE SCOPE */ /** @@ -474,6 +488,20 @@ Application.Controllers.controller('NewProjectController', ['$rootScope', '$scop $scope.matchingMembers = []; + /* + * Overlap global function to allow the user to navigate to the previous screen + * If no previous $state were recorded, navigate to the project list page + */ + $scope.backPrevLocation = function (event) { + event.preventDefault(); + event.stopPropagation(); + if ($state.prevState === '') { + $state.prevState = 'app.public.projects_list'; + return $state.go($state.prevState, {}); + } + window.history.back(); + }; + // Using the ProjectsController return new ProjectsController($rootScope, $scope, $state, Project, Machine, Member, Component, Theme, Licence, $document, Diacritics, dialogs, allowedExtensions, _t); } @@ -502,6 +530,19 @@ Application.Controllers.controller('EditProjectController', ['$rootScope', '$sco }); }); + /** + * Overlap global function to allow the user to navigate to the previous screen + * If no previous $state were recorded, navigate to the project show page + */ + $scope.backPrevLocation = function (event) { + event.preventDefault(); + event.stopPropagation(); + if ($state.prevState === '') { + $state.prevState = 'app.public.projects_show'; + } + $state.go($state.prevState, { id: $transition$.params().id }); + }; + /* PRIVATE SCOPE */ /** @@ -639,5 +680,19 @@ Application.Controllers.controller('ShowProjectController', ['$scope', '$state', * Return the URL allowing to share the current project on the Twitter social network */ $scope.shareOnTwitter = function () { return `https://twitter.com/intent/tweet?url=${encodeURIComponent($state.href('app.public.projects_show', { id: $scope.project.slug }, { absolute: true }))}&text=${encodeURIComponent($scope.project.name)}`; }; + + /** + * Overlap global function to allow the user to navigate to the previous screen + * If no previous $state were recorded, navigate to the project list page + */ + $scope.backPrevLocation = function (event) { + event.preventDefault(); + event.stopPropagation(); + if ($state.prevState === '') { + $state.prevState = 'app.public.projects_list'; + return $state.go($state.prevState, {}); + } + window.history.back(); + }; } ]);