From 27e690b35fc9842efbb8a8d7afbd211171b362f8 Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Sat, 14 Jan 2017 19:51:49 +0100 Subject: [PATCH] fix issue with wrong body class being applied on load --- app/scripts/main/global-services/projects-s.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/scripts/main/global-services/projects-s.js b/app/scripts/main/global-services/projects-s.js index aa8c0c36ae..a76405c9df 100644 --- a/app/scripts/main/global-services/projects-s.js +++ b/app/scripts/main/global-services/projects-s.js @@ -15,7 +15,7 @@ /* @ngInject */ function Projects(LS_DEFAULTS, $localStorage, $rootScope, Uid, $window, SimpleToast) { - const OMITTED_LS_FIELDS = ['currentProject', 'projects', '$$hashKey', '$$mdSelectId']; + const OMITTED_LS_FIELDS = ['currentProject', 'projects', '$$hashKey', '$$mdSelectId', 'bodyClass']; this.getList = () => { return $localStorage.projects; @@ -91,6 +91,16 @@ } }; + this.removeOmittedFields = (newCurrentProject) => { + if (newCurrentProject) { + for (let property in newCurrentProject.data) { + if (newCurrentProject.data.hasOwnProperty(property) && OMITTED_LS_FIELDS.indexOf(property) > -1) { + delete newCurrentProject.data[property]; + } + } + } + }; + $rootScope.$watch('r.currentProject', (newCurrentProject, oldCurrentProject) => { if (newCurrentProject && newCurrentProject.id) { // when there is an old current project existing @@ -100,6 +110,8 @@ } // update with new model fields, if we change the model this.updateNewFields(newCurrentProject); + // remove omitted fields if we saved them for some reason + this.removeOmittedFields(newCurrentProject); // update $rootScope data and ls for current project $rootScope.r.currentProject = $localStorage.currentProject = newCurrentProject;