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/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..92d39c4e 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 = () => { + 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/js/models/advice/edit.js b/src/js/models/advice/edit.js index b883fda6..90e7971f 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,23 +50,48 @@ const Model = function () { self.init = function () { self.locations(auth.getLocationsForUser([{ id: 'general', name: 'General Advice' }])) - 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) - + if (result.data.parentScenario !== null) { + self.parentScenarioKey(result.data.parentScenario.key) + } + else { + self.parentScenarioKey(null) + } 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 9919e626..683f3a62 100644 --- a/src/pages/advice/add/index.hbs +++ b/src/pages/advice/add/index.hbs @@ -43,6 +43,14 @@ 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