From c490da31457e5200306c128f47531c713a35ed56 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Fri, 18 Jun 2021 10:25:01 -0700 Subject: [PATCH 01/16] UX: Add wizard message component to submissions page --- .../discourse/controllers/admin-wizards-submissions.js.es6 | 6 ++++++ .../discourse/templates/admin-wizards-submissions.hbs | 5 +++++ config/locales/client.en.yml | 3 +++ 3 files changed, 14 insertions(+) create mode 100644 assets/javascripts/discourse/controllers/admin-wizards-submissions.js.es6 diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions.js.es6 new file mode 100644 index 00000000..b5b9365a --- /dev/null +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions.js.es6 @@ -0,0 +1,6 @@ +import Controller from "@ember/controller"; + +export default Controller.extend({ + messageKey: "select", + documentationUrl: "https://thepavilion.io/t/2818", +}); diff --git a/assets/javascripts/discourse/templates/admin-wizards-submissions.hbs b/assets/javascripts/discourse/templates/admin-wizards-submissions.hbs index d843485a..5a660790 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-submissions.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-submissions.hbs @@ -8,6 +8,11 @@ )}} +{{wizard-message + key=messageKey + url=documentationUrl + component="submissions"}} +
{{outlet}}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 43b86698..fa3a6c5d 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -91,6 +91,9 @@ en: destroying: Destroying wizards... import_complete: Import complete destroy_complete: Destruction complete + submissions: + select: "Select a wizard to see its submissions" + documentation: "Check out the submissions documentation" editor: show: "Show" From 10c7c8bcc09721ae917dba6ef9f97524449da8de Mon Sep 17 00:00:00 2001 From: Keegan George Date: Fri, 18 Jun 2021 11:25:51 -0700 Subject: [PATCH 02/16] UX: Change info message when selecting a wizard in the submissions pane --- .../admin-wizards-submissions.js.es6 | 30 ++++++++++++++++++- .../templates/admin-wizards-submissions.hbs | 3 +- config/locales/client.en.yml | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions.js.es6 index b5b9365a..7388a8d6 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions.js.es6 @@ -1,6 +1,34 @@ import Controller from "@ember/controller"; +import { default as discourseComputed } from "discourse-common/utils/decorators"; export default Controller.extend({ - messageKey: "select", documentationUrl: "https://thepavilion.io/t/2818", + + @discourseComputed("wizardId") + wizardName(wizardId) { + let currentWizard = this.wizardList.find( + (wizard) => wizard.id === wizardId + ); + if (currentWizard) { + return currentWizard.name; + } + }, + + @discourseComputed("wizardName") + messageOpts(wizardName) { + return { + wizardName, + }; + }, + + @discourseComputed("wizardId") + messageKey(wizardId) { + let key = "select"; + + if (wizardId) { + key = "viewing"; + } + + return key; + }, }); diff --git a/assets/javascripts/discourse/templates/admin-wizards-submissions.hbs b/assets/javascripts/discourse/templates/admin-wizards-submissions.hbs index 5a660790..07dd1682 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-submissions.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-submissions.hbs @@ -1,4 +1,4 @@ -
+
{{combo-box value=wizardId content=wizardList @@ -10,6 +10,7 @@ {{wizard-message key=messageKey + opts=messageOpts url=documentationUrl component="submissions"}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index fa3a6c5d..31f10924 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -93,6 +93,7 @@ en: destroy_complete: Destruction complete submissions: select: "Select a wizard to see its submissions" + viewing: "You're viewing the logs of the %{wizardName}. Click 'Download' on the right to download them." documentation: "Check out the submissions documentation" editor: From dd8513a56390f5b254441783fccf23a72c748575 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Fri, 18 Jun 2021 11:47:24 -0700 Subject: [PATCH 03/16] UX: Add wizard-message component to logs pane --- .../discourse/controllers/admin-wizards-logs.js.es6 | 2 ++ .../javascripts/discourse/templates/admin-wizards-logs.hbs | 6 ++++++ config/locales/client.en.yml | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/assets/javascripts/discourse/controllers/admin-wizards-logs.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-logs.js.es6 index 9559b01b..f45013d7 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-logs.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-logs.js.es6 @@ -9,6 +9,8 @@ export default Controller.extend({ page: 0, canLoadMore: true, logs: [], + documentationUrl: "https://thepavilion.io/t/2818", + messageKey: "viewing", loadLogs() { if (!this.canLoadMore) { diff --git a/assets/javascripts/discourse/templates/admin-wizards-logs.hbs b/assets/javascripts/discourse/templates/admin-wizards-logs.hbs index 18fd3fdb..33402cce 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-logs.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-logs.hbs @@ -8,6 +8,12 @@ class="refresh"}}
+{{wizard-message + key=messageKey + opts=messageOpts + url=documentationUrl + component="logs"}} + {{#load-more selector=".log-list tr" action=(action "loadMore") class="wizard-logs"}} {{#if noResults}}

{{i18n "search.no_results"}}

diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 31f10924..569f252f 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -95,6 +95,10 @@ en: select: "Select a wizard to see its submissions" viewing: "You're viewing the logs of the %{wizardName}. Click 'Download' on the right to download them." documentation: "Check out the submissions documentation" + logs: + viewing: "View recent logs for wizards on the forum" + documentation: "Check out the logs documentation" + editor: show: "Show" From 55b92f4256745a6be2e60c7940f31303c918186f Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Wed, 21 Jul 2021 11:31:03 +0800 Subject: [PATCH 04/16] IMPROVE: Add additional data to submission serialiser --- lib/custom_wizard/wizard.rb | 4 ++- .../custom_wizard/submission_serializer.rb | 30 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/custom_wizard/wizard.rb b/lib/custom_wizard/wizard.rb index e8427334..e52feec4 100644 --- a/lib/custom_wizard/wizard.rb +++ b/lib/custom_wizard/wizard.rb @@ -32,7 +32,8 @@ class CustomWizard::Wizard :actions, :action_ids, :user, - :submissions + :submissions, + :template attr_reader :all_step_ids @@ -79,6 +80,7 @@ class CustomWizard::Wizard @actions = attrs['actions'] || [] @action_ids = @actions.map { |a| a['id'] } + @template = attrs end def cast_bool(val) diff --git a/serializers/custom_wizard/submission_serializer.rb b/serializers/custom_wizard/submission_serializer.rb index 992deacb..f9cc7230 100644 --- a/serializers/custom_wizard/submission_serializer.rb +++ b/serializers/custom_wizard/submission_serializer.rb @@ -1,13 +1,33 @@ # frozen_string_literal: true class CustomWizard::SubmissionSerializer < ApplicationSerializer attributes :id, - :username, + :user, :fields, :submitted_at - def username - object.user.present? ? - object.user.username : - I18n.t('admin.wizard.submission.no_user', user_id: object.user_id) + has_one :user, serializer: ::BasicUserSerializer, embed: :objects + + def include_user? + object.user.present? + end + + def fields + @fields ||= begin + result = {} + + object.wizard.template['steps'].each do |step| + step['fields'].each do |field| + if value = object.fields[field['id']] + result[field['id']] = { + value: value, + type: field['type'], + label: field['label'] + } + end + end + end + + result + end end end From 51038ade8a1caefe663b4c9a8cf63ee9f7684beb Mon Sep 17 00:00:00 2001 From: Keegan George Date: Mon, 26 Jul 2021 10:44:08 -0700 Subject: [PATCH 05/16] FIX: Update help text in wizard message bar --- config/locales/client.en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index e7c10b52..ce253455 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -93,7 +93,7 @@ en: destroy_complete: Destruction complete submissions: select: "Select a wizard to see its submissions" - viewing: "You're viewing the logs of the %{wizardName}. Click 'Download' on the right to download them." + viewing: "You're viewing the submissions of the %{wizardName}. Click 'Download' on the right to download them." documentation: "Check out the submissions documentation" logs: viewing: "View recent logs for wizards on the forum" From 03fb7b7adab3780fc0860ed8da27cc144861095c Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Wed, 25 Aug 2021 09:59:24 +0800 Subject: [PATCH 06/16] WIP: update field data handling to support column toggling --- .../admin-wizards-submissions-show.js.es6 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 index 6352b3b2..28a1c825 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 @@ -24,6 +24,18 @@ export default Controller.extend({ this.set("loadingMore", false); }); }, + + + @discourseComputed('submissions', 'fields.@each.enabled') + displaySubmissions(submissions, fields) { + return submissions.map(submission => { + let field = fields.find(f => Object.keys(submission).includes(f.id)); + if (!field.enabled) { + submission.delete(field.id); + }; + return submission; + }); + }, actions: { loadMore() { From d74d3d25beecae7011b9c102726f8d074cb8f66c Mon Sep 17 00:00:00 2001 From: Keegan George Date: Mon, 30 Aug 2021 16:23:33 -0700 Subject: [PATCH 07/16] UX: Display submission fields unique to each type --- .../components/submission-field.js.es6 | 114 ++++++++++++++++++ .../admin-wizards-submissions-show.hbs | 20 ++- .../templates/components/submission-field.hbs | 114 ++++++++++++++++++ assets/stylesheets/common/wizard-admin.scss | 51 ++++++++ config/locales/client.en.yml | 6 + plugin.rb | 7 ++ 6 files changed, 307 insertions(+), 5 deletions(-) create mode 100644 assets/javascripts/discourse/components/submission-field.js.es6 create mode 100644 assets/javascripts/discourse/templates/components/submission-field.hbs diff --git a/assets/javascripts/discourse/components/submission-field.js.es6 b/assets/javascripts/discourse/components/submission-field.js.es6 new file mode 100644 index 00000000..f76376a5 --- /dev/null +++ b/assets/javascripts/discourse/components/submission-field.js.es6 @@ -0,0 +1,114 @@ +import { action } from "@ember/object"; +import Component from "@ember/component"; +import { equal } from "@ember/object/computed"; +import discourseComputed from "discourse-common/utils/decorators"; +import I18n from "I18n"; + + +export default Component.extend({ + isText: equal("value.type", "text"), + isComposer: equal("value.type", "composer"), + isDate: equal("value.type", "date"), + isTime: equal("value.type", "time"), + isDateTime: equal("value.type", "date_time"), + isNumber: equal("value.type", "number"), + isCheckbox: equal("value.type", "checkbox"), + isUrl: equal("value.type", "url"), + isUpload: equal("value.type", "upload"), + isDropdown: equal("value.type", "dropdown"), + isTag: equal("value.type", "tag"), + isCategory: equal("value.type", "category"), + isGroup: equal("value.type", "group"), + isUser: equal("fieldName", "username"), + isUserSelector: equal("value.type", "user_selector"), + isSubmittedAt: equal("fieldName", "submitted_at"), + isTextArea: equal("value.type", "textarea"), + isComposerPreview: equal("value.type", "composer_preview"), + textState: "text-collapsed", + toggleText: I18n.t('admin.wizard.submissions.expand_text'), + + @discourseComputed("value") + checkboxValue(value) { + const isCheckbox = this.get("isCheckbox"); + if (isCheckbox) { + if (value.value.includes("true")) { + return true; + } else if (value.value.includes("false")) { + return false; + } + } + }, + + @action + expandText() { + const state = this.get("textState"); + + if (state === "text-collapsed") { + this.set("textState", "text-expanded"); + this.set("toggleText", I18n.t('admin.wizard.submissions.collapse_text')); + } else if (state === "text-expanded") { + this.set("textState", "text-collapsed"); + this.set("toggleText", I18n.t('admin.wizard.submissions.expand_text')); + } + }, + + @discourseComputed('value') + file(value) { + const isUpload = this.get("isUpload"); + if (isUpload) { + return value.value; + } + }, + + @discourseComputed('value') + submittedUsers(value) { + const isUserSelector = this.get("isUserSelector"); + const users = []; + + if (isUserSelector) { + const userData = value.value; + const usernames = []; + + if (userData.indexOf(',')) { + usernames.push(...userData.split(',')); + + usernames.forEach(u => { + const user = { + username: u, + url: `/u/${u}` + } + users.push(user); + }) + } + } + return users; + }, + + @discourseComputed('value') + userProfileUrl(value) { + const isUser = this.get("isUser"); + const isUserSelector = this.get("isUserSelector"); + + if (isUser) { + return `/u/${value.username}`; + } + }, + + @discourseComputed('value') + categoryUrl(value) { + const isCategory = this.get('isCategory'); + + if (isCategory) { + return `/c/${value.value}`; + } + }, + + @discourseComputed('value') + groupUrl(value) { + const isGroup = this.get('isGroup'); + + if (isGroup) { + return `/g/${value.value}`; + } + }, +}); diff --git a/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs b/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs index 9e8e10c8..2f0689b1 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs @@ -2,6 +2,14 @@
+
+ {{d-button + icon="sliders-h" + label="admin.wizard.submissions.edit_columns" + action=(action "showEditColumnsModal") + class="btn-default open-edit-columns-btn download-link"}} +
+ {{d-icon "download"}} @@ -18,16 +26,18 @@ - {{#each fields as |f|}} - + {{#each fields as |field|}} + {{#if field.enabled}} + + {{/if}} {{/each}} - {{#each submissions as |s|}} + {{#each displaySubmissions as |submission|}} - {{#each-in s as |k v|}} - + {{#each-in submission as |field value|}} + {{/each-in}} {{/each}} diff --git a/assets/javascripts/discourse/templates/components/submission-field.hbs b/assets/javascripts/discourse/templates/components/submission-field.hbs new file mode 100644 index 00000000..52cde1dd --- /dev/null +++ b/assets/javascripts/discourse/templates/components/submission-field.hbs @@ -0,0 +1,114 @@ +{{#if isText}} + {{value.value}} +{{/if}} + +{{#if isTextArea}} +
+

{{value.value}}

+ {{toggleText}} +
+{{/if}} + +{{#if isComposer}} +
+

{{value.value}}

+ {{toggleText}} +
+{{/if}} + +{{#if isComposerPreview}} + {{d-icon "comment-alt" }} {{i18n "admin.wizard.submissions.composer_preview"}}: {{value.value}} +{{/if}} + +{{#if isTextOnly}} + {{value.value}} +{{/if}} + +{{#if isDate}} + + {{d-icon "calendar"}}{{value.value}} + +{{/if}} + +{{#if isTime}} + + {{d-icon "clock"}}{{value.value}} + +{{/if}} + +{{#if isDateTime}} + + {{d-icon "calendar"}}{{format-date value.value format="medium"}} + +{{/if}} + +{{#if isNumber}} + {{value.value}} +{{/if}} + +{{#if isCheckbox}} + {{#if checkboxValue}} + + {{d-icon "check"}}{{value.value}} + + {{else}} + + {{d-icon "times"}}{{value.value}} + + {{/if}} +{{/if}} + +{{#if isUrl}} + + {{ d-icon "link" }} + + {{value.value}} + + +{{/if}} + +{{#if isUpload}} + + {{file.original_filename}} + +{{/if}} + +{{#if isDropdown}} + + {{ d-icon "check-square" }} + {{ value.value }} + +{{/if}} + +{{#if isTag}} + {{#each value.value as |tag|}} + {{discourse-tag tag}} + {{/each}} +{{/if}} + +{{#if isCategory}} + {{i18n "admin.wizard.submissions.category_id"}}: {{value.value}} +{{/if}} + +{{#if isGroup}} + {{i18n "admin.wizard.submissions.group_id"}}: {{ value.value }} +{{/if}} + + +{{#if isUserSelector}} + {{#each submittedUsers as |user|}} + {{ d-icon "user" }} + {{user.username}} + {{/each}} +{{/if}} + +{{#if isUser}} + {{#link-to "user" value}}{{avatar value imageSize="tiny"}}{{/link-to}} + {{value.username}} +{{/if}} + +{{#if isSubmittedAt}} + + {{d-icon "clock"}}{{format-date value format="tiny"}} + +{{/if}} diff --git a/assets/stylesheets/common/wizard-admin.scss b/assets/stylesheets/common/wizard-admin.scss index 66cc6b43..66c8d2f7 100644 --- a/assets/stylesheets/common/wizard-admin.scss +++ b/assets/stylesheets/common/wizard-admin.scss @@ -71,6 +71,51 @@ table td { min-width: 150px; } + + table thead th { + text-transform: capitalize; + } + + .submission-icon-item { + display: flex; + align-items: center; + svg { + margin-right: 5px; + } + } + + .submission-checkbox-true { + text-transform: capitalize; + color: var(--success); + } + + .submission-checkbox-false { + text-transform: capitalize; + color: var(--danger); + } + + .submission-long-text { + &-content { + white-space: nowrap; + word-wrap: break-word; + overflow: hidden; + text-overflow: ellipsis; + width: 250px; + margin-bottom: 0; + + &.text-expanded { + white-space: normal; + } + } + + a { + font-size: var(--font-down-1); + } + } + + .submission-composer-text { + font-family: monospace; + } } .admin-wizards-logs { @@ -203,6 +248,11 @@ &.underline { text-decoration: underline; } + + .controls { + margin-left: auto; + margin-right: 0.5rem; + } } .admin-wizard-buttons { @@ -715,3 +765,4 @@ width: 80px; vertical-align: middle; } + diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index ce253455..8501e2a2 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -367,6 +367,12 @@ en: nav_label: "Submissions" title: "{{name}} Submissions" download: "Download" + edit_columns: "Edit Columns" + expand_text: "Read More" + collapse_text: "Show Less" + group_id: "Group ID" + category_id: "Category ID" + composer_preview: "Composer Preview" api: label: "API" diff --git a/plugin.rb b/plugin.rb index 449d0237..993fe0d5 100644 --- a/plugin.rb +++ b/plugin.rb @@ -33,6 +33,13 @@ if respond_to?(:register_svg_icon) register_svg_icon "chevron-right" register_svg_icon "chevron-left" register_svg_icon "save" + register_svg_icon "sliders-h" + register_svg_icon "calendar" + register_svg_icon "check" + register_svg_icon "times" + register_svg_icon "clock" + register_svg_icon "link" + register_svg_icon "comment-alt" end class ::Sprockets::DirectiveProcessor From 0bc151fc7b4c17b9d19ed2e138dd724fe3c44eab Mon Sep 17 00:00:00 2001 From: Keegan George Date: Mon, 30 Aug 2021 16:33:48 -0700 Subject: [PATCH 08/16] WIP: Edit Columns modal functionality Currently modal and edit columns works but removes only field and not corresponding submission. --- .../admin-wizards-submissions-columns.js.es6 | 16 ++++++++++ .../admin-wizards-submissions-show.js.es6 | 19 +++++++++-- .../discourse/models/custom-wizard.js.es6 | 24 +++++++------- .../admin-wizards-submissions-show.js.es6 | 12 +++++-- .../admin-wizards-submissions-columns.hbs | 32 +++++++++++++++++++ 5 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 create mode 100644 assets/javascripts/discourse/templates/modal/admin-wizards-submissions-columns.hbs diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 new file mode 100644 index 00000000..5627dacf --- /dev/null +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 @@ -0,0 +1,16 @@ +import Controller from "@ember/controller"; +import ModalFunctionality from "discourse/mixins/modal-functionality"; + +export default Controller.extend(ModalFunctionality, { + + actions: { + save() { + this.send("closeModal"); + }, + resetToDefault() { + this.get('model.fields').forEach(field => { + field.set("enabled", true); + }); + } + } +}); \ No newline at end of file diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 index 28a1c825..40a08f4f 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 @@ -2,6 +2,9 @@ import Controller from "@ember/controller"; import { fmt } from "discourse/lib/computed"; import { empty } from "@ember/object/computed"; import CustomWizard from "../models/custom-wizard"; +import showModal from "discourse/lib/show-modal"; +import discourseComputed from "discourse-common/utils/decorators"; + export default Controller.extend({ downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download"), @@ -31,8 +34,11 @@ export default Controller.extend({ return submissions.map(submission => { let field = fields.find(f => Object.keys(submission).includes(f.id)); if (!field.enabled) { - submission.delete(field.id); - }; + // insert field / submission deletion code here: + console.log(field, "is not enabled for ", submission); + } else if (field.enabled) { + console.log(field, "is enabled for ", submission); + } return submission; }); }, @@ -44,5 +50,14 @@ export default Controller.extend({ this.loadMoreSubmissions(); } }, + + showEditColumnsModal() { + const controller = showModal("admin-wizards-submissions-columns", { + model: { + fields: this.get('fields'), + submissions: this.get('submissions') + } + }); + }, }, }); diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index 5e94e31e..d9a2bafa 100644 --- a/assets/javascripts/discourse/models/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard.js.es6 @@ -224,31 +224,33 @@ CustomWizard.reopenClass({ }) .then((result) => { if (result.wizard) { - let fields = ["username"]; + console.log(result); + let fields = [{ id: "username", label: "User"}]; let submissions = []; let wizard = result.wizard; let total = result.total; result.submissions.forEach((s) => { let submission = { - username: s.username, + username: s.user, }; - Object.keys(s.fields).forEach((f) => { - if (fields.indexOf(f) < 0) { - fields.push(f); - } - - if (fields.includes(f)) { - submission[f] = s.fields[f]; + Object.keys(s.fields).forEach((fieldId) => { + if (!fields.some(field => field.id === fieldId)) { + fields.push({ id: fieldId, label: s.fields[fieldId].label }); } + submission[fieldId] = s.fields[fieldId]; }); - submission["submitted_at"] = s.submitted_at; submissions.push(submission); }); - fields.push("submitted_at"); + let submittedAt = { + id: "submitted_at", + label: "Submitted At" + } + + fields.push(submittedAt); return { wizard, diff --git a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 index 2ff9fbf9..829d4d13 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 @@ -1,6 +1,7 @@ -import CustomWizard from "../models/custom-wizard"; -import DiscourseRoute from "discourse/routes/discourse"; import { A } from "@ember/array"; +import EmberObject from "@ember/object"; +import DiscourseRoute from "discourse/routes/discourse"; +import CustomWizard from "../models/custom-wizard"; export default DiscourseRoute.extend({ model(params) { @@ -8,9 +9,14 @@ export default DiscourseRoute.extend({ }, setupController(controller, model) { + const fields = model.fields.map((f) => { + const fieldsObject = EmberObject.create(f); + fieldsObject.enabled = true; + return fieldsObject; + }); controller.setProperties({ wizard: model.wizard, - fields: model.fields, + fields: A(fields), submissions: A(model.submissions), total: model.total, }); diff --git a/assets/javascripts/discourse/templates/modal/admin-wizards-submissions-columns.hbs b/assets/javascripts/discourse/templates/modal/admin-wizards-submissions-columns.hbs new file mode 100644 index 00000000..a167a954 --- /dev/null +++ b/assets/javascripts/discourse/templates/modal/admin-wizards-submissions-columns.hbs @@ -0,0 +1,32 @@ +{{#d-modal-body title="directory.edit_columns.title"}} + {{#if loading}} + {{loading-spinner size="large"}} + {{else}} +
+ {{#each model.fields as |field|}} +
+
+ +
+
+ {{/each}} +
+ {{/if}} +{{/d-modal-body}} + + From 280d2ffe54e4a9e3debe95deafa7bc419665707b Mon Sep 17 00:00:00 2001 From: Keegan George Date: Tue, 31 Aug 2021 13:29:30 -0700 Subject: [PATCH 09/16] IMPROVE: Make edit columns adjust submissions as well --- .../admin-wizards-submissions-show.js.es6 | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 index 40a08f4f..2667b6b2 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 @@ -31,16 +31,20 @@ export default Controller.extend({ @discourseComputed('submissions', 'fields.@each.enabled') displaySubmissions(submissions, fields) { - return submissions.map(submission => { - let field = fields.find(f => Object.keys(submission).includes(f.id)); - if (!field.enabled) { - // insert field / submission deletion code here: - console.log(field, "is not enabled for ", submission); - } else if (field.enabled) { - console.log(field, "is enabled for ", submission); - } - return submission; + let result = []; + + submissions.forEach(submission => { + let sub = {}; + + Object.keys(submission).forEach(fieldId => { + if (fields.some(f => f.id === fieldId && f.enabled)) { + sub[fieldId] = submission[fieldId]; + } + }); + result.push(sub); }); + + return result; }, actions: { From 7b13605c7bb51f3bd3ca351b65f7f1726b6b64d4 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Wed, 1 Sep 2021 12:46:39 -0700 Subject: [PATCH 10/16] FIX: Resolve linting issues --- .../discourse/components/submission-field.js.es6 | 9 ++++----- .../controllers/admin-wizards-submissions-columns.js.es6 | 2 +- .../controllers/admin-wizards-submissions-show.js.es6 | 6 +++--- assets/javascripts/discourse/models/custom-wizard.js.es6 | 5 ++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/assets/javascripts/discourse/components/submission-field.js.es6 b/assets/javascripts/discourse/components/submission-field.js.es6 index f76376a5..ea9e34cf 100644 --- a/assets/javascripts/discourse/components/submission-field.js.es6 +++ b/assets/javascripts/discourse/components/submission-field.js.es6 @@ -64,21 +64,21 @@ export default Component.extend({ submittedUsers(value) { const isUserSelector = this.get("isUserSelector"); const users = []; - + if (isUserSelector) { const userData = value.value; const usernames = []; - if (userData.indexOf(',')) { + if (userData.indexOf(',')) { usernames.push(...userData.split(',')); usernames.forEach(u => { const user = { username: u, url: `/u/${u}` - } + }; users.push(user); - }) + }); } } return users; @@ -87,7 +87,6 @@ export default Component.extend({ @discourseComputed('value') userProfileUrl(value) { const isUser = this.get("isUser"); - const isUserSelector = this.get("isUserSelector"); if (isUser) { return `/u/${value.username}`; diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 index 5627dacf..981d1139 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 @@ -2,7 +2,7 @@ import Controller from "@ember/controller"; import ModalFunctionality from "discourse/mixins/modal-functionality"; export default Controller.extend(ModalFunctionality, { - + actions: { save() { this.send("closeModal"); diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 index 2667b6b2..450f7d53 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 @@ -27,8 +27,8 @@ export default Controller.extend({ this.set("loadingMore", false); }); }, - - + + @discourseComputed('submissions', 'fields.@each.enabled') displaySubmissions(submissions, fields) { let result = []; @@ -56,7 +56,7 @@ export default Controller.extend({ }, showEditColumnsModal() { - const controller = showModal("admin-wizards-submissions-columns", { + return showModal("admin-wizards-submissions-columns", { model: { fields: this.get('fields'), submissions: this.get('submissions') diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index d9a2bafa..660ba4ee 100644 --- a/assets/javascripts/discourse/models/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard.js.es6 @@ -224,7 +224,6 @@ CustomWizard.reopenClass({ }) .then((result) => { if (result.wizard) { - console.log(result); let fields = [{ id: "username", label: "User"}]; let submissions = []; let wizard = result.wizard; @@ -248,8 +247,8 @@ CustomWizard.reopenClass({ let submittedAt = { id: "submitted_at", label: "Submitted At" - } - + }; + fields.push(submittedAt); return { From 9fc2092951bb22a2daf61883552c3dc13f680488 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Thu, 2 Sep 2021 15:38:30 -0700 Subject: [PATCH 11/16] =?UTF-8?q?DEV:=20Run=20prettier=20=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/submission-field.js.es6 | 31 +++++++++---------- .../admin-wizards-submissions-show.js.es6 | 22 ++++++------- .../discourse/models/custom-wizard.js.es6 | 16 +++++----- .../admin-wizards-submissions-columns.hbs | 2 +- 4 files changed, 34 insertions(+), 37 deletions(-) diff --git a/assets/javascripts/discourse/components/submission-field.js.es6 b/assets/javascripts/discourse/components/submission-field.js.es6 index ea9e34cf..5ebc0ccd 100644 --- a/assets/javascripts/discourse/components/submission-field.js.es6 +++ b/assets/javascripts/discourse/components/submission-field.js.es6 @@ -1,10 +1,9 @@ -import { action } from "@ember/object"; import Component from "@ember/component"; +import { action } from "@ember/object"; import { equal } from "@ember/object/computed"; import discourseComputed from "discourse-common/utils/decorators"; import I18n from "I18n"; - export default Component.extend({ isText: equal("value.type", "text"), isComposer: equal("value.type", "composer"), @@ -25,7 +24,7 @@ export default Component.extend({ isTextArea: equal("value.type", "textarea"), isComposerPreview: equal("value.type", "composer_preview"), textState: "text-collapsed", - toggleText: I18n.t('admin.wizard.submissions.expand_text'), + toggleText: I18n.t("admin.wizard.submissions.expand_text"), @discourseComputed("value") checkboxValue(value) { @@ -45,14 +44,14 @@ export default Component.extend({ if (state === "text-collapsed") { this.set("textState", "text-expanded"); - this.set("toggleText", I18n.t('admin.wizard.submissions.collapse_text')); + this.set("toggleText", I18n.t("admin.wizard.submissions.collapse_text")); } else if (state === "text-expanded") { this.set("textState", "text-collapsed"); - this.set("toggleText", I18n.t('admin.wizard.submissions.expand_text')); + this.set("toggleText", I18n.t("admin.wizard.submissions.expand_text")); } }, - @discourseComputed('value') + @discourseComputed("value") file(value) { const isUpload = this.get("isUpload"); if (isUpload) { @@ -60,7 +59,7 @@ export default Component.extend({ } }, - @discourseComputed('value') + @discourseComputed("value") submittedUsers(value) { const isUserSelector = this.get("isUserSelector"); const users = []; @@ -69,13 +68,13 @@ export default Component.extend({ const userData = value.value; const usernames = []; - if (userData.indexOf(',')) { - usernames.push(...userData.split(',')); + if (userData.indexOf(",")) { + usernames.push(...userData.split(",")); - usernames.forEach(u => { + usernames.forEach((u) => { const user = { username: u, - url: `/u/${u}` + url: `/u/${u}`, }; users.push(user); }); @@ -84,7 +83,7 @@ export default Component.extend({ return users; }, - @discourseComputed('value') + @discourseComputed("value") userProfileUrl(value) { const isUser = this.get("isUser"); @@ -93,18 +92,18 @@ export default Component.extend({ } }, - @discourseComputed('value') + @discourseComputed("value") categoryUrl(value) { - const isCategory = this.get('isCategory'); + const isCategory = this.get("isCategory"); if (isCategory) { return `/c/${value.value}`; } }, - @discourseComputed('value') + @discourseComputed("value") groupUrl(value) { - const isGroup = this.get('isGroup'); + const isGroup = this.get("isGroup"); if (isGroup) { return `/g/${value.value}`; diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 index 450f7d53..7ba0050f 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 @@ -1,10 +1,9 @@ import Controller from "@ember/controller"; -import { fmt } from "discourse/lib/computed"; import { empty } from "@ember/object/computed"; -import CustomWizard from "../models/custom-wizard"; -import showModal from "discourse/lib/show-modal"; import discourseComputed from "discourse-common/utils/decorators"; - +import { fmt } from "discourse/lib/computed"; +import showModal from "discourse/lib/show-modal"; +import CustomWizard from "../models/custom-wizard"; export default Controller.extend({ downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download"), @@ -28,16 +27,15 @@ export default Controller.extend({ }); }, - - @discourseComputed('submissions', 'fields.@each.enabled') + @discourseComputed("submissions", "fields.@each.enabled") displaySubmissions(submissions, fields) { let result = []; - submissions.forEach(submission => { + submissions.forEach((submission) => { let sub = {}; - Object.keys(submission).forEach(fieldId => { - if (fields.some(f => f.id === fieldId && f.enabled)) { + Object.keys(submission).forEach((fieldId) => { + if (fields.some((f) => f.id === fieldId && f.enabled)) { sub[fieldId] = submission[fieldId]; } }); @@ -58,9 +56,9 @@ export default Controller.extend({ showEditColumnsModal() { return showModal("admin-wizards-submissions-columns", { model: { - fields: this.get('fields'), - submissions: this.get('submissions') - } + fields: this.get("fields"), + submissions: this.get("submissions"), + }, }); }, }, diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index 660ba4ee..d0b49079 100644 --- a/assets/javascripts/discourse/models/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard.js.es6 @@ -1,10 +1,10 @@ -import { ajax } from "discourse/lib/ajax"; import EmberObject from "@ember/object"; -import { buildProperties, mapped, present } from "../lib/wizard-json"; -import { listProperties, snakeCase } from "../lib/wizard"; -import wizardSchema from "../lib/wizard-schema"; -import { Promise } from "rsvp"; +import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; +import { Promise } from "rsvp"; +import { listProperties, snakeCase } from "../lib/wizard"; +import { buildProperties, mapped, present } from "../lib/wizard-json"; +import wizardSchema from "../lib/wizard-schema"; const CustomWizard = EmberObject.extend({ save(opts) { @@ -224,7 +224,7 @@ CustomWizard.reopenClass({ }) .then((result) => { if (result.wizard) { - let fields = [{ id: "username", label: "User"}]; + let fields = [{ id: "username", label: "User" }]; let submissions = []; let wizard = result.wizard; let total = result.total; @@ -235,7 +235,7 @@ CustomWizard.reopenClass({ }; Object.keys(s.fields).forEach((fieldId) => { - if (!fields.some(field => field.id === fieldId)) { + if (!fields.some((field) => field.id === fieldId)) { fields.push({ id: fieldId, label: s.fields[fieldId].label }); } submission[fieldId] = s.fields[fieldId]; @@ -246,7 +246,7 @@ CustomWizard.reopenClass({ let submittedAt = { id: "submitted_at", - label: "Submitted At" + label: "Submitted At", }; fields.push(submittedAt); diff --git a/assets/javascripts/discourse/templates/modal/admin-wizards-submissions-columns.hbs b/assets/javascripts/discourse/templates/modal/admin-wizards-submissions-columns.hbs index a167a954..24743a92 100644 --- a/assets/javascripts/discourse/templates/modal/admin-wizards-submissions-columns.hbs +++ b/assets/javascripts/discourse/templates/modal/admin-wizards-submissions-columns.hbs @@ -29,4 +29,4 @@ label="directory.edit_columns.reset_to_default" action=(action "resetToDefault") }} - + \ No newline at end of file From 1e38001942fc13e5e379d6415dd1033fb49d9d89 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Thu, 2 Sep 2021 15:41:55 -0700 Subject: [PATCH 12/16] =?UTF-8?q?DEV:=20Run=20Prettier=20=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/admin-wizards-submissions-columns.js.es6 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 index 981d1139..4af487ee 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 @@ -2,15 +2,14 @@ import Controller from "@ember/controller"; import ModalFunctionality from "discourse/mixins/modal-functionality"; export default Controller.extend(ModalFunctionality, { - actions: { save() { this.send("closeModal"); }, resetToDefault() { - this.get('model.fields').forEach(field => { + this.get("model.fields").forEach((field) => { field.set("enabled", true); }); - } - } -}); \ No newline at end of file + }, + }, +}); From 4abe30464c1b29ff2234aab1bc0387022e7c07a4 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Thu, 2 Sep 2021 15:43:34 -0700 Subject: [PATCH 13/16] =?UTF-8?q?DEV:=20Run=20Prettier=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin-wizards-submissions-show.hbs | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs b/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs index 2f0689b1..6f4996f6 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs @@ -1,16 +1,24 @@ {{#if submissions}}
- +
{{d-button - icon="sliders-h" - label="admin.wizard.submissions.edit_columns" + icon="sliders-h" + label="admin.wizard.submissions.edit_columns" action=(action "showEditColumnsModal") - class="btn-default open-edit-columns-btn download-link"}} + class="btn-default open-edit-columns-btn download-link" + }}
- + {{d-icon "download"}} {{i18n "admin.wizard.submissions.download"}} @@ -21,14 +29,18 @@
{{#load-more selector=".wizard-submissions tr" action=(action "loadMore")}} {{#if noResults}} -

{{i18n "search.no_results"}}

+

+ {{i18n "search.no_results"}} +

{{else}}
{{f}}{{field.label}}
{{v}}{{submission-field fieldName=field value=value}}
{{#each fields as |field|}} {{#if field.enabled}} - + {{/if}} {{/each}} @@ -37,7 +49,9 @@ {{#each displaySubmissions as |submission|}} {{#each-in submission as |field value|}} - + {{/each-in}} {{/each}} @@ -48,4 +62,4 @@ {{conditional-loading-spinner condition=loadingMore}} {{/load-more}} -{{/if}} +{{/if}} \ No newline at end of file From c60d1e33386fa48cc31dde63ffca0f3a4f51bad9 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Thu, 2 Sep 2021 15:46:49 -0700 Subject: [PATCH 14/16] =?UTF-8?q?DEV:=20Run=20Prettier=20=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/components/submission-field.hbs | 97 ++++++++++++++----- 1 file changed, 73 insertions(+), 24 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/submission-field.hbs b/assets/javascripts/discourse/templates/components/submission-field.hbs index 52cde1dd..831dcc3a 100644 --- a/assets/javascripts/discourse/templates/components/submission-field.hbs +++ b/assets/javascripts/discourse/templates/components/submission-field.hbs @@ -4,20 +4,35 @@ {{#if isTextArea}} {{/if}} {{#if isComposer}}
-

{{value.value}}

- {{toggleText}} +

+ {{value.value}} +

+ + {{toggleText}} +
{{/if}} {{#if isComposerPreview}} - {{d-icon "comment-alt" }} {{i18n "admin.wizard.submissions.composer_preview"}}: {{value.value}} + {{d-icon "comment-alt"}} + + {{i18n "admin.wizard.submissions.composer_preview"}}: {{value.value}} + {{/if}} {{#if isTextOnly}} @@ -48,35 +63,41 @@ {{#if isCheckbox}} {{#if checkboxValue}} - - {{d-icon "check"}}{{value.value}} - + + {{d-icon "check"}}{{value.value}} + {{else}} - - {{d-icon "times"}}{{value.value}} - + + {{d-icon "times"}}{{value.value}} + {{/if}} {{/if}} {{#if isUrl}} - {{ d-icon "link" }} - + {{d-icon "link"}} + {{value.value}} {{/if}} {{#if isUpload}} - + {{file.original_filename}} {{/if}} {{#if isDropdown}} - {{ d-icon "check-square" }} - {{ value.value }} + {{d-icon "check-square"}} + {{value.value}} {{/if}} @@ -87,28 +108,56 @@ {{/if}} {{#if isCategory}} - {{i18n "admin.wizard.submissions.category_id"}}: {{value.value}} + + {{i18n "admin.wizard.submissions.category_id"}}: + + + {{value.value}} + {{/if}} {{#if isGroup}} - {{i18n "admin.wizard.submissions.group_id"}}: {{ value.value }} + + {{i18n "admin.wizard.submissions.group_id"}}: + + {{value.value}} {{/if}} - {{#if isUserSelector}} {{#each submittedUsers as |user|}} - {{ d-icon "user" }} - {{user.username}} + {{d-icon "user"}} + + {{user.username}} + {{/each}} {{/if}} {{#if isUser}} - {{#link-to "user" value}}{{avatar value imageSize="tiny"}}{{/link-to}} - {{value.username}} + {{#link-to "user" value}} + {{avatar value imageSize="tiny"}} + {{/link-to}} + + {{value.username}} + {{/if}} {{#if isSubmittedAt}} {{d-icon "clock"}}{{format-date value format="tiny"}} -{{/if}} +{{/if}} \ No newline at end of file From f6c3c98d7183aed6efc84e22e550af60526414af Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Mon, 6 Sep 2021 17:25:08 +0800 Subject: [PATCH 15/16] Add submission serializer spec --- .../custom_wizard/submission_serializer.rb | 1 - .../submission_serializer_spec.rb | 51 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 spec/serializers/custom_wizard/submission_serializer_spec.rb diff --git a/serializers/custom_wizard/submission_serializer.rb b/serializers/custom_wizard/submission_serializer.rb index f9cc7230..e5e88867 100644 --- a/serializers/custom_wizard/submission_serializer.rb +++ b/serializers/custom_wizard/submission_serializer.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true class CustomWizard::SubmissionSerializer < ApplicationSerializer attributes :id, - :user, :fields, :submitted_at diff --git a/spec/serializers/custom_wizard/submission_serializer_spec.rb b/spec/serializers/custom_wizard/submission_serializer_spec.rb new file mode 100644 index 00000000..d3f3e7fc --- /dev/null +++ b/spec/serializers/custom_wizard/submission_serializer_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require_relative '../../plugin_helper' + +describe CustomWizard::SubmissionSerializer do + fab!(:user) { Fabricate(:user) } + + let(:template_json) { + JSON.parse(File.open( + "#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/wizard.json" + ).read) + } + + before do + CustomWizard::Template.save(template_json, skip_jobs: true) + wizard = CustomWizard::Wizard.create(template_json["id"], user) + CustomWizard::Submission.new(wizard, + step_1_field_1: "I am user submission", + submitted_at: Time.now.iso8601 + ).save + @list = CustomWizard::Submission.list(wizard, page: 0) + end + + it 'should return submission attributes' do + json_array = ActiveModel::ArraySerializer.new( + @list.submissions, + each_serializer: described_class + ).as_json + + expect(json_array.length).to eq(1) + expect(json_array[0][:id].present?).to eq(true) + expect(json_array[0][:user].present?).to eq(true) + expect(json_array[0][:submitted_at].present?).to eq(true) + end + + it "should return field values, types and labels" do + json_array = ActiveModel::ArraySerializer.new( + @list.submissions, + each_serializer: described_class + ).as_json + + expect(json_array.length).to eq(1) + expect(json_array[0][:fields].as_json).to eq({ + "step_1_field_1": { + "value": "I am user submission", + "type": "text", + "label": "Text" + } + }.as_json) + end +end From 31b9e48c8ff11340d1cfa437c0fea1f4afe39833 Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Mon, 6 Sep 2021 17:26:22 +0800 Subject: [PATCH 16/16] Apply rubocop --- spec/serializers/custom_wizard/submission_serializer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/serializers/custom_wizard/submission_serializer_spec.rb b/spec/serializers/custom_wizard/submission_serializer_spec.rb index d3f3e7fc..02d8be8a 100644 --- a/spec/serializers/custom_wizard/submission_serializer_spec.rb +++ b/spec/serializers/custom_wizard/submission_serializer_spec.rb @@ -18,7 +18,7 @@ describe CustomWizard::SubmissionSerializer do step_1_field_1: "I am user submission", submitted_at: Time.now.iso8601 ).save - @list = CustomWizard::Submission.list(wizard, page: 0) + @list = CustomWizard::Submission.list(wizard, page: 0) end it 'should return submission attributes' do
{{field.label}} + {{field.label}} +
{{submission-field fieldName=field value=value}} + {{submission-field fieldName=field value=value}} +