[SEBA-136] Resetting default feedback config when xosForm is removed
Change-Id: I18641b05001fa6b55e7976ae85695c5865571933
diff --git a/Dockerfile b/Dockerfile
index a01467f..79ca1a1 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,7 +2,7 @@
# docker build -f Dockerfile -t xosproject/xos-gui:candidate .
# xos-gui-base container
-FROM xosproject/xos-gui-builder:1.0.0 as xos-gui-base
+FROM xosproject/xos-gui-builder:1.0.5 as xos-gui-base
ENV CODE_SOURCE .
ENV CODE_DEST /var/www
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..923ce93
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,56 @@
+# Copyright 2019-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Configure shell
+SHELL = bash -e -o pipefail
+
+# Variables
+VERSION ?= $(shell python -c 'import json,sys;obj=json.load(sys.stdin); print obj["version"]' < package.json)
+SERVICE_NAME ?= $(notdir $(abspath .))
+
+## Docker related
+DOCKER_REGISTRY ?=
+DOCKER_REPOSITORY ?=
+DOCKER_BUILD_ARGS ?=
+DOCKER_TAG ?= ${VERSION}
+DOCKER_IMAGENAME := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${SERVICE_NAME}:${DOCKER_TAG}
+
+## Docker labels. Only set ref and commit date if committed
+DOCKER_LABEL_VCS_URL ?= $(shell git remote get-url $(shell git remote))
+DOCKER_LABEL_VCS_REF ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
+DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
+DOCKER_LABEL_BUILD_DATE ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
+
+all: test
+
+docker-build:
+ docker build $(DOCKER_BUILD_ARGS) \
+ -t ${DOCKER_IMAGENAME} \
+ --build-arg org_label_schema_version="${VERSION}" \
+ --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
+ --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
+ --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
+ --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
+ -f Dockerfile .
+
+docker-push:
+ docker push ${DOCKER_IMAGENAME}
+
+test: test-unit
+
+node_modules:
+ npm install
+
+test-unit: node_modules
+ npm run test
diff --git a/src/app/core/form/form.spec.ts b/src/app/core/form/form.spec.ts
index 1be9a43..e0180b6 100644
--- a/src/app/core/form/form.spec.ts
+++ b/src/app/core/form/form.spec.ts
@@ -175,6 +175,13 @@
compileElement();
}));
+ it('should reset the feedback state $onDestroy', () => {
+ isolatedScope.config.feedback = 'foo';
+ expect(isolatedScope.config.feedback).toEqual('foo');
+ isolatedScope.$onDestroy();
+ expect(isolatedScope.config.feedback).toEqual(isolatedScope.hideFeedback);
+ });
+
it('should render 4 input field', () => {
// boolean and select are in the form model, but are not input
expect(Object.keys(isolatedScope.config.inputs).length).toEqual(6);
diff --git a/src/app/core/form/form.ts b/src/app/core/form/form.ts
index 1c10c33..fa54c6f 100644
--- a/src/app/core/form/form.ts
+++ b/src/app/core/form/form.ts
@@ -72,19 +72,28 @@
}
class FormCtrl {
- $inject = ['$onInit', '$scope', 'XosFormHelpers'];
+ $inject = ['$onInit', '$onDestroy', '$scope', 'XosFormHelpers', '$log'];
public ngModel: any;
public formField: any;
private config: any;
+ private hideFeedback: IXosFeedback = {
+ show: false,
+ message: 'Form submitted successfully !!!',
+ type: 'success',
+ closeBtn: true
+ };
+
constructor (
private $scope: ng.IScope,
+ private $log: angular.ILogService,
private XosFormHelpers: IXosFormHelpersService
) {
}
$onInit() {
+ this.$log.debug('[xosForm] Init component');
if (!this.config) {
throw new Error('[xosForm] Please provide a configuration via the "config" attribute');
}
@@ -99,12 +108,7 @@
// NOTE needed to avoid xosAlert throw an error
if (!this.config.feedback) {
- this.config.feedback = {
- show: false,
- message: 'Form submitted successfully !!!',
- type: 'success',
- closeBtn: true
- };
+ this.config.feedback = this.hideFeedback;
}
// remove excluded inputs
@@ -112,6 +116,11 @@
_.remove(this.config.inputs, i => this.config.exclude.indexOf(i.name) > -1);
}
}
+
+ $onDestroy() {
+ this.$log.debug('[xosForm] Destroying component');
+ this.config.feedback = this.hideFeedback;
+ }
}
export const xosForm: angular.IComponentOptions = {