From 153050b49d8ec61b06a88d9a459cfb87d141ac3c Mon Sep 17 00:00:00 2001 From: Oleksandr Seliuchenko Date: Tue, 22 Sep 2020 15:42:55 +0300 Subject: [PATCH 1/4] Added parent scenarios --- src/js/api-endpoints.js | 3 ++- src/js/models/advice/add.js | 24 +++++++++++++++++++++++- src/pages/advice/add/index.hbs | 10 ++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/js/api-endpoints.js b/src/js/api-endpoints.js index 0b4daa50..54a09ec9 100644 --- a/src/js/api-endpoints.js +++ b/src/js/api-endpoints.js @@ -42,5 +42,6 @@ module.exports = { users: p('/v1/users'), verifiedUsers: p('/v1/verified-users'), volunteerCategories: p('/v1/volunteer-categories'), - volunteers: p('/v1/volunteer-enquiries') + volunteers: p('/v1/volunteer-enquiries'), + parentScenarios: p('/v1/parent-scenarios') } diff --git a/src/js/models/advice/add.js b/src/js/models/advice/add.js index f4f10131..cc7bbcaf 100644 --- a/src/js/models/advice/add.js +++ b/src/js/models/advice/add.js @@ -4,6 +4,7 @@ const ajax = require('../../ajax') const auth = require('../../auth') const browser = require('../../browser') const endpoints = require('../../api-endpoints') +const htmlEncode = require('htmlencode') const BaseViewModel = require('../BaseViewModel') @@ -17,6 +18,8 @@ const Model = function () { self.sortPosition = ko.observable() self.locationKey = ko.observable() self.locations = ko.observableArray() + self.parentScenarios= ko.observableArray() + self.parentScenarioKey = ko.observable() self.save = function () { browser.loading() @@ -27,7 +30,8 @@ const Model = function () { ? self.tags().split(',').map((t) => t.trim()) : [], locationKey: self.locationKey(), - sortPosition: self.sortPosition() + sortPosition: self.sortPosition(), + parentScenario: self.parentScenarios().find((ps) => ps.key === self.parentScenarioKey()) } ajax .post(endpoints.faqs, payload) @@ -45,6 +49,24 @@ const Model = function () { self.init = function () { self.locations(auth.getLocationsForUser([{ id: 'general', name: 'General Advice' }])) + self.getParentScenarios() + } + + self.getParentScenarios = (locationId) => { + ajax + .get(`${endpoints.parentScenarios}`) + .then((result) => { + self.parentScenarios(result.data + .map(p => { + return { + key: p.key, + name: htmlEncode.htmlDecode(p.name) + } + }) + ) + }, () => { + self.handleServerError() + }) } } diff --git a/src/pages/advice/add/index.hbs b/src/pages/advice/add/index.hbs index 9919e626..48bb8bc5 100644 --- a/src/pages/advice/add/index.hbs +++ b/src/pages/advice/add/index.hbs @@ -43,6 +43,16 @@ nosubnav: true optionsText: function (item) { return item.name }, optionsCaption: '-- please select --'" class="form__input"> + +
Parent Scenario
+
+ +
+
Body
From 59007cce2569a4bdb723b141bef7c9fb20e869da Mon Sep 17 00:00:00 2001 From: Oleksandr Seliuchenko Date: Tue, 22 Sep 2020 16:55:04 +0300 Subject: [PATCH 2/4] Update advice editing --- spec/advice/add/happyPathSpec.js | 6 ++++-- src/js/models/advice/add.js | 2 +- src/js/models/advice/edit.js | 27 ++++++++++++++++++++++++--- src/pages/advice/add/index.hbs | 2 -- src/pages/advice/edit/index.hbs | 10 +++++++++- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/spec/advice/add/happyPathSpec.js b/spec/advice/add/happyPathSpec.js index 510b85a9..86a06d36 100644 --- a/spec/advice/add/happyPathSpec.js +++ b/spec/advice/add/happyPathSpec.js @@ -57,7 +57,8 @@ describe('Advice QA - Add', () => { model.locationKey('location') model.tags('tag-a , tag-b, tag-c ') model.sortPosition(123) - + model.parentScenarioKey('parent-scenario') + model.parentScenarios([{ key: 'parent-scenario', name: 'Parent scenario' }, { key: 'parent-scenario2', name: 'Parent scenario 2' }]) model.save() }) @@ -74,7 +75,8 @@ describe('Advice QA - Add', () => { body: 'body', locationKey: 'location', tags: ['tag-a', 'tag-b', 'tag-c'], - sortPosition: 123 + sortPosition: 123, + parentScenario: { key: 'parent-scenario', name: 'Parent scenario' } } expect(payload).toEqual(expected) }) diff --git a/src/js/models/advice/add.js b/src/js/models/advice/add.js index cc7bbcaf..c90328ba 100644 --- a/src/js/models/advice/add.js +++ b/src/js/models/advice/add.js @@ -52,7 +52,7 @@ const Model = function () { self.getParentScenarios() } - self.getParentScenarios = (locationId) => { + self.getParentScenarios = () => { ajax .get(`${endpoints.parentScenarios}`) .then((result) => { diff --git a/src/js/models/advice/edit.js b/src/js/models/advice/edit.js index b883fda6..af2accb6 100644 --- a/src/js/models/advice/edit.js +++ b/src/js/models/advice/edit.js @@ -5,6 +5,7 @@ const ajax = require('../../ajax') const auth = require('../../auth') const browser = require('../../browser') const querystring = require('../../get-url-parameter') +const endpoints = require('../../api-endpoints') const BaseViewModel = require('../BaseViewModel') @@ -18,6 +19,8 @@ const Model = function () { self.sortPosition = ko.observable() self.locationKey = ko.observable() self.locations = ko.observableArray() + self.parentScenarios= ko.observableArray() + self.parentScenarioKey = ko.observable() self.save = function () { browser.loading() @@ -28,7 +31,8 @@ const Model = function () { ? self.tags().split(',').map((t) => t.trim()) : [], locationKey: self.locationKey(), - sortPosition: self.sortPosition() + sortPosition: self.sortPosition(), + parentScenario: self.parentScenarios().find((ps) => ps.key === self.parentScenarioKey()) } ajax .put(self.endpointBuilder.faqs(querystring.parameter('id')).build(), payload) @@ -46,8 +50,8 @@ const Model = function () { self.init = function () { self.locations(auth.getLocationsForUser([{ id: 'general', name: 'General Advice' }])) - browser.loading() + self.getParentScenarios() ajax .get(self.endpointBuilder.faqs(querystring.parameter('id')).build()) @@ -57,12 +61,29 @@ const Model = function () { self.locationKey(result.data.locationKey) self.tags(result.data.tags.join(', ')) self.sortPosition(result.data.sortPosition) - + self.parentScenarioKey(result.data.parentScenario.key) browser.loaded() }, (err) => { self.handleError(err) }) } + + self.getParentScenarios = () => { + ajax + .get(`${endpoints.parentScenarios}`) + .then((result) => { + self.parentScenarios(result.data + .map(p => { + return { + key: p.key, + name: htmlencode.htmlDecode(p.name) + } + }) + ) + }, () => { + self.handleServerError() + }) + } } Model.prototype = new BaseViewModel() diff --git a/src/pages/advice/add/index.hbs b/src/pages/advice/add/index.hbs index 48bb8bc5..683f3a62 100644 --- a/src/pages/advice/add/index.hbs +++ b/src/pages/advice/add/index.hbs @@ -43,7 +43,6 @@ nosubnav: true optionsText: function (item) { return item.name }, optionsCaption: '-- please select --'" class="form__input">
-
Parent Scenario
-
Body
diff --git a/src/pages/advice/edit/index.hbs b/src/pages/advice/edit/index.hbs index 59a3a855..f065ad04 100644 --- a/src/pages/advice/edit/index.hbs +++ b/src/pages/advice/edit/index.hbs @@ -11,7 +11,7 @@ nosubnav: true
-

Add Location Advice Q&A Content

+

Edit Location Advice Q&A Content

Back to Listing @@ -36,6 +36,14 @@ nosubnav: true optionsText: function (item) { return item.name }, optionsCaption: '-- please select --'" class="form__input">
+
Parent Scenario
+
+ +
Body
From a5e9e87704ba7eeb256ea56e7d92c11622ed95fe Mon Sep 17 00:00:00 2001 From: Oleksandr Seliuchenko Date: Thu, 24 Sep 2020 17:57:57 +0300 Subject: [PATCH 3/4] Fix bug on editing page --- src/js/models/advice/add.js | 2 +- src/js/models/advice/edit.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/js/models/advice/add.js b/src/js/models/advice/add.js index c90328ba..92d39c4e 100644 --- a/src/js/models/advice/add.js +++ b/src/js/models/advice/add.js @@ -18,7 +18,7 @@ const Model = function () { self.sortPosition = ko.observable() self.locationKey = ko.observable() self.locations = ko.observableArray() - self.parentScenarios= ko.observableArray() + self.parentScenarios= ko.observableArray([]) self.parentScenarioKey = ko.observable() self.save = function () { diff --git a/src/js/models/advice/edit.js b/src/js/models/advice/edit.js index af2accb6..98eb14d1 100644 --- a/src/js/models/advice/edit.js +++ b/src/js/models/advice/edit.js @@ -19,7 +19,7 @@ const Model = function () { self.sortPosition = ko.observable() self.locationKey = ko.observable() self.locations = ko.observableArray() - self.parentScenarios= ko.observableArray() + self.parentScenarios= ko.observableArray([]) self.parentScenarioKey = ko.observable() self.save = function () { @@ -61,7 +61,7 @@ const Model = function () { self.locationKey(result.data.locationKey) self.tags(result.data.tags.join(', ')) self.sortPosition(result.data.sortPosition) - self.parentScenarioKey(result.data.parentScenario.key) + self.parentScenarioKey(result.data.parentScenario !== null ? result.data.parentScenario.key : null) browser.loaded() }, (err) => { self.handleError(err) From ceef0a9ff6f3d3e05ca8f4feec1d67c370660974 Mon Sep 17 00:00:00 2001 From: Oleksandr Seliuchenko Date: Mon, 28 Sep 2020 11:11:31 +0300 Subject: [PATCH 4/4] Fix issue regarding refreshing edited item --- src/js/models/advice/edit.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/js/models/advice/edit.js b/src/js/models/advice/edit.js index 98eb14d1..90e7971f 100644 --- a/src/js/models/advice/edit.js +++ b/src/js/models/advice/edit.js @@ -53,15 +53,23 @@ const Model = function () { browser.loading() self.getParentScenarios() + // We generate this for retrieving the not cached item + let syntaxSugar = new Date().getTime() + ajax - .get(self.endpointBuilder.faqs(querystring.parameter('id')).build()) + .get(self.endpointBuilder.faqs(querystring.parameter('id')).build() + `?unique=${syntaxSugar}`) .then((result) => { self.title(htmlencode.htmlDecode(result.data.title)) self.body(htmlencode.htmlDecode(result.data.body)) self.locationKey(result.data.locationKey) self.tags(result.data.tags.join(', ')) self.sortPosition(result.data.sortPosition) - self.parentScenarioKey(result.data.parentScenario !== null ? result.data.parentScenario.key : null) + if (result.data.parentScenario !== null) { + self.parentScenarioKey(result.data.parentScenario.key) + } + else { + self.parentScenarioKey(null) + } browser.loaded() }, (err) => { self.handleError(err)