From c490da31457e5200306c128f47531c713a35ed56 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Fri, 18 Jun 2021 10:25:01 -0700 Subject: [PATCH 01/39] 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/39] 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/39] 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 34fee3729cb4e5c62a94e5875436eabee7099777 Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Wed, 14 Jul 2021 14:04:19 +0800 Subject: [PATCH 04/39] Add pagination to submissions --- .../admin-wizards-submissions-show.js.es6 | 28 ++++++++++++ .../discourse/models/custom-wizard.js.es6 | 44 ++++++++++++++++++- .../admin-wizards-submissions-show.js.es6 | 38 +++------------- .../admin-wizards-submissions-show.hbs | 44 +++++++++++-------- .../custom_wizard/admin/submissions.rb | 12 +++-- lib/custom_wizard/submission.rb | 30 +++++++++---- lib/custom_wizard/wizard.rb | 2 +- .../custom_wizard/submission_serializer.rb | 5 +-- .../custom_wizard/submission_spec.rb | 15 +++++-- 9 files changed, 146 insertions(+), 72 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 f5f9926d..bc38648d 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 @@ -1,6 +1,34 @@ import Controller from "@ember/controller"; import { fmt } from "discourse/lib/computed"; +import { empty } from '@ember/object/computed'; +import CustomWizard from "../models/custom-wizard"; export default Controller.extend({ downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download"), + noResults: empty('submissions'), + page: 0, + total: 0, + + loadMoreSubmissions() { + const page = this.get('page'); + const wizardId = this.get('wizard.id'); + + this.set('loadingMore', true); + CustomWizard.submissions(wizardId, page).then(result => { + if (result.submissions) { + this.get('submissions').pushObjects(result.submissions); + } + }).finally(() => { + this.set('loadingMore', false); + }); + }, + + actions: { + loadMore() { + if (!this.loadingMore && (this.submissions.length < this.total)) { + this.set('page', this.get('page') + 1); + this.loadMoreSubmissions(); + } + } + } }); diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index e6a8408d..e4b0a530 100644 --- a/assets/javascripts/discourse/models/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard.js.es6 @@ -211,9 +211,51 @@ CustomWizard.reopenClass({ .catch(popupAjaxError); }, - submissions(wizardId) { + submissions(wizardId, page = null) { + let data = {}; + + if (page) { + data.page = page; + } + return ajax(`/admin/wizards/submissions/${wizardId}`, { type: "GET", + data + }).then(result => { + if (result.wizard) { + let fields = ["username"]; + let submissions = []; + let wizard = result.wizard; + let total = result.total; + + result.submissions.forEach((s) => { + let submission = { + username: s.username, + }; + + Object.keys(s.fields).forEach((f) => { + if (fields.indexOf(f) < 0) { + fields.push(f); + } + + if (fields.includes(f)) { + submission[f] = s.fields[f]; + } + }); + + submission['submitted_at'] = s.submitted_at; + submissions.push(submission); + }); + + fields.push("submitted_at"); + + return { + wizard, + fields, + submissions, + total + }; + } }).catch(popupAjaxError); }, 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 73168ff3..509816da 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 @@ -1,7 +1,6 @@ import CustomWizard from "../models/custom-wizard"; import DiscourseRoute from "discourse/routes/discourse"; - -const excludedMetaFields = ["route_to", "redirect_on_complete", "redirect_to"]; +import { A } from "@ember/array"; export default DiscourseRoute.extend({ model(params) { @@ -9,34 +8,11 @@ export default DiscourseRoute.extend({ }, setupController(controller, model) { - if (model && model.submissions) { - let fields = ["username"]; - model.submissions.forEach((s) => { - Object.keys(s.fields).forEach((k) => { - if (!excludedMetaFields.includes(k) && fields.indexOf(k) < 0) { - fields.push(k); - } - }); - }); - - let submissions = []; - model.submissions.forEach((s) => { - let submission = { - username: s.username, - }; - Object.keys(s.fields).forEach((f) => { - if (fields.includes(f)) { - submission[f] = s.fields[f]; - } - }); - submissions.push(submission); - }); - - controller.setProperties({ - wizard: model.wizard, - submissions, - fields, - }); - } + controller.setProperties({ + wizard: model.wizard, + fields: model.fields, + submissions: A(model.submissions), + total: model.total + }); }, }); diff --git a/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs b/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs index 6d1f255b..9e8e10c8 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs @@ -11,23 +11,31 @@
- - - - {{#each fields as |f|}} - - {{/each}} - - - - {{#each submissions as |s|}} - - {{#each-in s as |k v|}} - - {{/each-in}} - - {{/each}} - -
{{f}}
{{v}}
+ {{#load-more selector=".wizard-submissions tr" action=(action "loadMore")}} + {{#if noResults}} +

{{i18n "search.no_results"}}

+ {{else}} + + + + {{#each fields as |f|}} + + {{/each}} + + + + {{#each submissions as |s|}} + + {{#each-in s as |k v|}} + + {{/each-in}} + + {{/each}} + +
{{f}}
{{v}}
+ {{/if}} + + {{conditional-loading-spinner condition=loadingMore}} + {{/load-more}}
{{/if}} diff --git a/controllers/custom_wizard/admin/submissions.rb b/controllers/custom_wizard/admin/submissions.rb index 4cb2a0e4..c3bf809f 100644 --- a/controllers/custom_wizard/admin/submissions.rb +++ b/controllers/custom_wizard/admin/submissions.rb @@ -13,12 +13,16 @@ class CustomWizard::AdminSubmissionsController < CustomWizard::AdminController def show render_json_dump( wizard: CustomWizard::BasicWizardSerializer.new(@wizard, root: false), - submissions: ActiveModel::ArraySerializer.new(ordered_submissions, each_serializer: CustomWizard::SubmissionSerializer) + submissions: ActiveModel::ArraySerializer.new( + submission_list.submissions, + each_serializer: CustomWizard::SubmissionSerializer + ), + total: submission_list.total ) end def download - send_data ordered_submissions.to_json, + send_data submission_list.submissions.to_json, filename: "#{Discourse.current_hostname}-wizard-submissions-#{@wizard.name}.json", content_type: "application/json", disposition: "attachment" @@ -26,7 +30,7 @@ class CustomWizard::AdminSubmissionsController < CustomWizard::AdminController protected - def ordered_submissions - CustomWizard::Submission.list(@wizard, order_by: 'id') + def submission_list + CustomWizard::Submission.list(@wizard, page: params[:page].to_i) end end diff --git a/lib/custom_wizard/submission.rb b/lib/custom_wizard/submission.rb index e50cb259..95b4f7fa 100644 --- a/lib/custom_wizard/submission.rb +++ b/lib/custom_wizard/submission.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class CustomWizard::Submission include ActiveModel::SerializerSupport - + + PAGE_LIMIT = 50 KEY ||= "submissions" META ||= %w(submitted_at route_to redirect_on_complete redirect_to) @@ -44,7 +45,7 @@ class CustomWizard::Submission validate submission_list = self.class.list(wizard, user_id: user.id) - submissions = submission_list.select { |submission| submission.id != self.id } + submissions = submission_list.submissions.select { |submission| submission.id != self.id } submissions.push(self) submission_data = submissions.map { |submission| data_to_save(submission) } @@ -92,27 +93,38 @@ class CustomWizard::Submission end def self.get(wizard, user_id) - data = PluginStore.get("#{wizard.id}_#{KEY}", user_id).first + data = PluginStore.get("#{wizard.id}_#{KEY}", user_id).last new(wizard, data, user_id) end - def self.list(wizard, user_id: nil, order_by: nil) + def self.list(wizard, user_id: nil, page: nil) params = { plugin_name: "#{wizard.id}_#{KEY}" } params[:key] = user_id if user_id.present? query = PluginStoreRow.where(params) - query = query.order("#{order_by} DESC") if order_by.present? - - result = [] + result = OpenStruct.new(submissions: [], total: nil) query.each do |record| - if (submission_data = ::JSON.parse(record.value)).any? + if (submission_data = ::JSON.parse(record.value)).any? submission_data.each do |data| - result.push(new(wizard, data, record.key)) + result.submissions.push(new(wizard, data, record.key)) end end end + result.total = result.submissions.size + + if !page.nil? + start = page * PAGE_LIMIT + length = PAGE_LIMIT + + if result.submissions.length > start + result.submissions = result.submissions[start, length] + else + result.submissions = [] + end + end + result end end diff --git a/lib/custom_wizard/wizard.rb b/lib/custom_wizard/wizard.rb index 8f5a897f..e8427334 100644 --- a/lib/custom_wizard/wizard.rb +++ b/lib/custom_wizard/wizard.rb @@ -272,7 +272,7 @@ class CustomWizard::Wizard def submissions return nil unless user.present? - @submissions ||= CustomWizard::Submission.list(self, user_id: user.id) + @submissions ||= CustomWizard::Submission.list(self, user_id: user.id).submissions end def current_submission diff --git a/serializers/custom_wizard/submission_serializer.rb b/serializers/custom_wizard/submission_serializer.rb index 52f0cb32..992deacb 100644 --- a/serializers/custom_wizard/submission_serializer.rb +++ b/serializers/custom_wizard/submission_serializer.rb @@ -3,10 +3,7 @@ class CustomWizard::SubmissionSerializer < ApplicationSerializer attributes :id, :username, :fields, - :submitted_at, - :route_to, - :redirect_on_complete, - :redirect_to + :submitted_at def username object.user.present? ? diff --git a/spec/components/custom_wizard/submission_spec.rb b/spec/components/custom_wizard/submission_spec.rb index a8c33861..ce9756d1 100644 --- a/spec/components/custom_wizard/submission_spec.rb +++ b/spec/components/custom_wizard/submission_spec.rb @@ -21,8 +21,11 @@ describe CustomWizard::Submission do @wizard = CustomWizard::Wizard.create(template_json["id"], user) @wizard2 = CustomWizard::Wizard.create(template_json["id"], user2) @wizard3 = CustomWizard::Wizard.create(template_json_2["id"], user) + @count = CustomWizard::Submission::PAGE_LIMIT + 20 - described_class.new(@wizard, step_1_field_1: "I am a user submission").save + @count.times do |index| + described_class.new(@wizard, step_1_field_1: "I am user submission #{index+1}").save + end described_class.new(@wizard2, step_1_field_1: "I am another user's submission").save described_class.new(@wizard3, step_1_field_1: "I am a user submission on another wizard").save end @@ -30,14 +33,18 @@ describe CustomWizard::Submission do it "saves a user's submission" do expect( described_class.get(@wizard, user.id).fields["step_1_field_1"] - ).to eq("I am a user submission") + ).to eq("I am user submission #{@count}") end it "list submissions by wizard" do - expect(described_class.list(@wizard).size).to eq(2) + expect(described_class.list(@wizard).total).to eq(@count + 1) end it "list submissions by wizard and user" do - expect(described_class.list(@wizard, user_id: user.id).size).to eq(1) + expect(described_class.list(@wizard, user_id: user.id).total).to eq(@count) + end + + it "paginates submission lists" do + expect(described_class.list(@wizard, page: 1).submissions.size).to eq((@count + 1) - CustomWizard::Submission::PAGE_LIMIT) end end From 56a146341335d4ef768012b55821f3048dbda3c5 Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Wed, 14 Jul 2021 14:05:13 +0800 Subject: [PATCH 05/39] Apply prettier --- .../admin-wizards-submissions-show.js.es6 | 34 +++++----- .../discourse/models/custom-wizard.js.es6 | 64 ++++++++++--------- .../admin-wizards-submissions-show.js.es6 | 2 +- 3 files changed, 52 insertions(+), 48 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 bc38648d..6352b3b2 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-show.js.es6 @@ -1,34 +1,36 @@ import Controller from "@ember/controller"; import { fmt } from "discourse/lib/computed"; -import { empty } from '@ember/object/computed'; +import { empty } from "@ember/object/computed"; import CustomWizard from "../models/custom-wizard"; export default Controller.extend({ downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download"), - noResults: empty('submissions'), + noResults: empty("submissions"), page: 0, total: 0, loadMoreSubmissions() { - const page = this.get('page'); - const wizardId = this.get('wizard.id'); + const page = this.get("page"); + const wizardId = this.get("wizard.id"); - this.set('loadingMore', true); - CustomWizard.submissions(wizardId, page).then(result => { - if (result.submissions) { - this.get('submissions').pushObjects(result.submissions); - } - }).finally(() => { - this.set('loadingMore', false); - }); + this.set("loadingMore", true); + CustomWizard.submissions(wizardId, page) + .then((result) => { + if (result.submissions) { + this.get("submissions").pushObjects(result.submissions); + } + }) + .finally(() => { + this.set("loadingMore", false); + }); }, actions: { loadMore() { - if (!this.loadingMore && (this.submissions.length < this.total)) { - this.set('page', this.get('page') + 1); + if (!this.loadingMore && this.submissions.length < this.total) { + this.set("page", this.get("page") + 1); this.loadMoreSubmissions(); } - } - } + }, + }, }); diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index e4b0a530..5e94e31e 100644 --- a/assets/javascripts/discourse/models/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard.js.es6 @@ -220,43 +220,45 @@ CustomWizard.reopenClass({ return ajax(`/admin/wizards/submissions/${wizardId}`, { type: "GET", - data - }).then(result => { - if (result.wizard) { - let fields = ["username"]; - let submissions = []; - let wizard = result.wizard; - let total = result.total; + data, + }) + .then((result) => { + if (result.wizard) { + let fields = ["username"]; + let submissions = []; + let wizard = result.wizard; + let total = result.total; - result.submissions.forEach((s) => { - let submission = { - username: s.username, - }; + result.submissions.forEach((s) => { + let submission = { + username: s.username, + }; - Object.keys(s.fields).forEach((f) => { - if (fields.indexOf(f) < 0) { - fields.push(f); - } + Object.keys(s.fields).forEach((f) => { + if (fields.indexOf(f) < 0) { + fields.push(f); + } - if (fields.includes(f)) { - submission[f] = s.fields[f]; - } + if (fields.includes(f)) { + submission[f] = s.fields[f]; + } + }); + + submission["submitted_at"] = s.submitted_at; + submissions.push(submission); }); - - submission['submitted_at'] = s.submitted_at; - submissions.push(submission); - }); - fields.push("submitted_at"); + fields.push("submitted_at"); - return { - wizard, - fields, - submissions, - total - }; - } - }).catch(popupAjaxError); + return { + wizard, + fields, + submissions, + total, + }; + } + }) + .catch(popupAjaxError); }, create(wizardJson = {}) { 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 509816da..2ff9fbf9 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 @@ -12,7 +12,7 @@ export default DiscourseRoute.extend({ wizard: model.wizard, fields: model.fields, submissions: A(model.submissions), - total: model.total + total: model.total, }); }, }); From 1a78b44d35fa35b0192d5c72093d95817e172003 Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Wed, 14 Jul 2021 14:06:54 +0800 Subject: [PATCH 06/39] Apply rubocop --- lib/custom_wizard/submission.rb | 4 ++-- spec/components/custom_wizard/submission_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/custom_wizard/submission.rb b/lib/custom_wizard/submission.rb index 95b4f7fa..618a9a67 100644 --- a/lib/custom_wizard/submission.rb +++ b/lib/custom_wizard/submission.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class CustomWizard::Submission include ActiveModel::SerializerSupport - + PAGE_LIMIT = 50 KEY ||= "submissions" META ||= %w(submitted_at route_to redirect_on_complete redirect_to) @@ -105,7 +105,7 @@ class CustomWizard::Submission result = OpenStruct.new(submissions: [], total: nil) query.each do |record| - if (submission_data = ::JSON.parse(record.value)).any? + if (submission_data = ::JSON.parse(record.value)).any? submission_data.each do |data| result.submissions.push(new(wizard, data, record.key)) end diff --git a/spec/components/custom_wizard/submission_spec.rb b/spec/components/custom_wizard/submission_spec.rb index ce9756d1..fd7e8984 100644 --- a/spec/components/custom_wizard/submission_spec.rb +++ b/spec/components/custom_wizard/submission_spec.rb @@ -24,7 +24,7 @@ describe CustomWizard::Submission do @count = CustomWizard::Submission::PAGE_LIMIT + 20 @count.times do |index| - described_class.new(@wizard, step_1_field_1: "I am user submission #{index+1}").save + described_class.new(@wizard, step_1_field_1: "I am user submission #{index + 1}").save end described_class.new(@wizard2, step_1_field_1: "I am another user's submission").save described_class.new(@wizard3, step_1_field_1: "I am a user submission on another wizard").save From 55b92f4256745a6be2e60c7940f31303c918186f Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Wed, 21 Jul 2021 11:31:03 +0800 Subject: [PATCH 07/39] 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 08/39] 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 ae271ce647fcfb321000755aa91b98a30a0ffe89 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Mon, 9 Aug 2021 14:44:44 -0700 Subject: [PATCH 09/39] UX: Add support button to admin-nav (#118) * Add support button to admin-nav * FIX: Security vulnerabilities with _blank anchor link * Update pro support url * UX: Create pro button custom styling * UX: Merge support button focus styling with hover * DEV: Move pro support url to setting * UX: Change support button name to Pro Support * DEV: Format stylesheet code * DEV: Use variables and change selector specificity for pro button * DEV: Hardcode pro-support url in button * DEV: Remove support url localization * DEV: Undo formatting fixes and add pro support button strings * DEV: Undo formatting fixes auto applied * DEV: Add space between selectors * DEV: Convert scss variables to CSS Custom properties * DEV: Fix linting * FIX: Use SCSS variables for color manipulation functions * DEV: Fix space before i18n * DEV: Add new line at end of file * DEV: Add new line at end of file * DEV: Remove name attribute in localizations * DEV: Remove padding from new line --- .../discourse/templates/admin-wizards.hbs | 4 ++++ assets/stylesheets/common/wizard-admin.scss | 20 +++++++++++++++++++ .../stylesheets/common/wizard-variables.scss | 7 +++++++ config/locales/client.en.yml | 3 +++ plugin.rb | 1 + 5 files changed, 35 insertions(+) create mode 100644 assets/stylesheets/common/wizard-variables.scss diff --git a/assets/javascripts/discourse/templates/admin-wizards.hbs b/assets/javascripts/discourse/templates/admin-wizards.hbs index bd575aae..5baa9f52 100644 --- a/assets/javascripts/discourse/templates/admin-wizards.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards.hbs @@ -7,6 +7,10 @@ {{/if}} {{nav-item route="adminWizardsLogs" label="admin.wizard.log.nav_label"}} {{nav-item route="adminWizardsManager" label="admin.wizard.manager.nav_label"}} + + {{/admin-nav}}
diff --git a/assets/stylesheets/common/wizard-admin.scss b/assets/stylesheets/common/wizard-admin.scss index 66cc6b43..3c4f9ccf 100644 --- a/assets/stylesheets/common/wizard-admin.scss +++ b/assets/stylesheets/common/wizard-admin.scss @@ -2,6 +2,7 @@ @import "wizard-manager"; @import "wizard-api"; @import "common/components/buttons"; +@import "wizard-variables"; .admin-wizard-controls { display: flex; @@ -715,3 +716,22 @@ width: 80px; vertical-align: middle; } + +.btn.btn-pavilion-pro { + background: var(--pavilion-primary); + color: var(--pavilion-secondary); + + .d-icon { + color: var(--pavilion-secondary); + } + + &:hover, + &:focus { + background: darken($pavilionPrimary, 5%); + + &[href], + svg.d-icon { + color: darken($pavilionSecondary, 10%); + } + } +} diff --git a/assets/stylesheets/common/wizard-variables.scss b/assets/stylesheets/common/wizard-variables.scss new file mode 100644 index 00000000..68f02b6b --- /dev/null +++ b/assets/stylesheets/common/wizard-variables.scss @@ -0,0 +1,7 @@ +$pavilionPrimary: #3c1c8c; +$pavilionSecondary: #ffffff; + +:root { + --pavilion-primary: #3c1c8c; + --pavilion-secondary: #ffffff; +} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index ef826cab..16cbe883 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -58,6 +58,9 @@ en: select_type: "Select a type" condition: "Condition" index: "Index" + pro_support_button: + title: "Request Pro Support" + label: "Pro Support" message: wizard: diff --git a/plugin.rb b/plugin.rb index 449d0237..615ad81e 100644 --- a/plugin.rb +++ b/plugin.rb @@ -33,6 +33,7 @@ if respond_to?(:register_svg_icon) register_svg_icon "chevron-right" register_svg_icon "chevron-left" register_svg_icon "save" + register_svg_icon "far-life-ring" end class ::Sprockets::DirectiveProcessor From c1fc2fd0e49389671405ac2d916095c71b5c9966 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Tue, 10 Aug 2021 14:31:59 +0530 Subject: [PATCH 10/39] FIX: clear submission if skipped by user --- controllers/custom_wizard/wizard.rb | 2 +- lib/custom_wizard/submission.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/controllers/custom_wizard/wizard.rb b/controllers/custom_wizard/wizard.rb index e0cf669d..539b4b80 100644 --- a/controllers/custom_wizard/wizard.rb +++ b/controllers/custom_wizard/wizard.rb @@ -68,7 +68,7 @@ class CustomWizard::WizardController < ::ApplicationController result.merge!(redirect_to: submission.redirect_to) end - wizard.final_cleanup! + submission.remove if submission.present? end render json: result diff --git a/lib/custom_wizard/submission.rb b/lib/custom_wizard/submission.rb index e12299d1..8706d659 100644 --- a/lib/custom_wizard/submission.rb +++ b/lib/custom_wizard/submission.rb @@ -97,6 +97,21 @@ class CustomWizard::Submission new(wizard, data, user_id) end + def self.remove(submission) + if submission.present? + user_id = submission.user.id + wizard_id = submission.wizard.id + submission_id = submission.id + data = PluginStore.get("#{wizard_id}_#{KEY}", user_id) + data.delete_if { |sub| sub["id"] == submission_id} + PluginStore.set("#{wizard_id}_#{KEY}", user_id, data) + end + end + + def remove + self.class.remove(self) + end + def self.cleanup_incomplete_submissions(wizard) user_id = wizard.user.id all_submissions = list(wizard, user_id: user_id) From dee3691cd0799d24cb01eb6e3b5a49a909c819f7 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Tue, 10 Aug 2021 14:35:56 +0530 Subject: [PATCH 11/39] fix formatting --- lib/custom_wizard/submission.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/custom_wizard/submission.rb b/lib/custom_wizard/submission.rb index 8706d659..de33e817 100644 --- a/lib/custom_wizard/submission.rb +++ b/lib/custom_wizard/submission.rb @@ -103,7 +103,7 @@ class CustomWizard::Submission wizard_id = submission.wizard.id submission_id = submission.id data = PluginStore.get("#{wizard_id}_#{KEY}", user_id) - data.delete_if { |sub| sub["id"] == submission_id} + data.delete_if { |sub| sub["id"] == submission_id } PluginStore.set("#{wizard_id}_#{KEY}", user_id, data) end end From 89f733ae324666ea69599b65513b0f28015650d3 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Thu, 12 Aug 2021 17:11:58 +0530 Subject: [PATCH 12/39] added spec to verify functionality --- spec/requests/custom_wizard/wizard_controller_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/requests/custom_wizard/wizard_controller_spec.rb b/spec/requests/custom_wizard/wizard_controller_spec.rb index f2000bda..34628bda 100644 --- a/spec/requests/custom_wizard/wizard_controller_spec.rb +++ b/spec/requests/custom_wizard/wizard_controller_spec.rb @@ -76,4 +76,14 @@ describe CustomWizard::WizardController do put '/w/super-mega-fun-wizard/skip.json' expect(response.parsed_body['redirect_to']).to eq('/t/2') end + + it "deletes the submission if user has filled up some data" do + @wizard = CustomWizard::Wizard.create(@template["id"], user) + CustomWizard::Submission.new(@wizard, step_1_field_1: "Hello World").save + current_submission = @wizard.current_submission + put '/w/super-mega-fun-wizard/skip.json' + list = CustomWizard::Submission.list(@wizard) + + expect(list.any? { |submission| submission.id == current_submission.id }).to eq(false) + end end From 0d2f3d1cb52b917fc4c3cd838cfa295e883decff Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Thu, 12 Aug 2021 20:02:04 +0530 Subject: [PATCH 13/39] FIX: reset step progress on wizard skip --- controllers/custom_wizard/wizard.rb | 1 + lib/custom_wizard/wizard.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/controllers/custom_wizard/wizard.rb b/controllers/custom_wizard/wizard.rb index 539b4b80..1f259a59 100644 --- a/controllers/custom_wizard/wizard.rb +++ b/controllers/custom_wizard/wizard.rb @@ -69,6 +69,7 @@ class CustomWizard::WizardController < ::ApplicationController end submission.remove if submission.present? + wizard.cleanup! end render json: result diff --git a/lib/custom_wizard/wizard.rb b/lib/custom_wizard/wizard.rb index 8f5a897f..b4b3b8fd 100644 --- a/lib/custom_wizard/wizard.rb +++ b/lib/custom_wizard/wizard.rb @@ -286,11 +286,15 @@ class CustomWizard::Wizard end end - def final_cleanup! + def cleanup! if id == user.custom_fields['redirect_to_wizard'] user.custom_fields.delete('redirect_to_wizard') user.save_custom_fields(true) end + end + + def final_cleanup! + cleanup! if current_submission.present? current_submission.submitted_at = Time.now.iso8601 From bfa190e98b7c64f089d49733ee4ee984c4aebf78 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Fri, 13 Aug 2021 02:55:25 +0530 Subject: [PATCH 14/39] Revert "FIX: reset step progress on wizard skip" This reverts commit 0d2f3d1cb52b917fc4c3cd838cfa295e883decff. --- controllers/custom_wizard/wizard.rb | 1 - lib/custom_wizard/wizard.rb | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/controllers/custom_wizard/wizard.rb b/controllers/custom_wizard/wizard.rb index 1f259a59..539b4b80 100644 --- a/controllers/custom_wizard/wizard.rb +++ b/controllers/custom_wizard/wizard.rb @@ -69,7 +69,6 @@ class CustomWizard::WizardController < ::ApplicationController end submission.remove if submission.present? - wizard.cleanup! end render json: result diff --git a/lib/custom_wizard/wizard.rb b/lib/custom_wizard/wizard.rb index b4b3b8fd..8f5a897f 100644 --- a/lib/custom_wizard/wizard.rb +++ b/lib/custom_wizard/wizard.rb @@ -286,15 +286,11 @@ class CustomWizard::Wizard end end - def cleanup! + def final_cleanup! if id == user.custom_fields['redirect_to_wizard'] user.custom_fields.delete('redirect_to_wizard') user.save_custom_fields(true) end - end - - def final_cleanup! - cleanup! if current_submission.present? current_submission.submitted_at = Time.now.iso8601 From 61c92ec7680905159c893fa9beb0a5217436039a Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Fri, 13 Aug 2021 17:49:31 +0530 Subject: [PATCH 15/39] FIX: reset user's progress on wizard skip --- controllers/custom_wizard/wizard.rb | 1 + lib/custom_wizard/wizard.rb | 8 ++++++++ .../requests/custom_wizard/wizard_controller_spec.rb | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/controllers/custom_wizard/wizard.rb b/controllers/custom_wizard/wizard.rb index 539b4b80..bb692ebb 100644 --- a/controllers/custom_wizard/wizard.rb +++ b/controllers/custom_wizard/wizard.rb @@ -69,6 +69,7 @@ class CustomWizard::WizardController < ::ApplicationController end submission.remove if submission.present? + wizard.reset_user_progress! end render json: result diff --git a/lib/custom_wizard/wizard.rb b/lib/custom_wizard/wizard.rb index 8f5a897f..5adfbf1a 100644 --- a/lib/custom_wizard/wizard.rb +++ b/lib/custom_wizard/wizard.rb @@ -286,6 +286,14 @@ class CustomWizard::Wizard end end + def reset_user_progress! + UserHistory.where( + action: UserHistory.actions[:custom_wizard_step], + acting_user_id: user.id, + context: id + ).destroy_all + end + def final_cleanup! if id == user.custom_fields['redirect_to_wizard'] user.custom_fields.delete('redirect_to_wizard') diff --git a/spec/requests/custom_wizard/wizard_controller_spec.rb b/spec/requests/custom_wizard/wizard_controller_spec.rb index 34628bda..4cd47c80 100644 --- a/spec/requests/custom_wizard/wizard_controller_spec.rb +++ b/spec/requests/custom_wizard/wizard_controller_spec.rb @@ -86,4 +86,16 @@ describe CustomWizard::WizardController do expect(list.any? { |submission| submission.id == current_submission.id }).to eq(false) end + + it "starts from the first step if user visits after skipping the wizard" do + put '/w/super-mega-fun-wizard/steps/step_1.json', params: { + fields: { + step_1_field_1: "Text input" + } + } + put '/w/super-mega-fun-wizard/skip.json' + get '/w/super-mega-fun-wizard.json' + + expect(response.parsed_body["start"]).to eq('step_1') + end end From 4578cb0a24567177f4bc6b4101111710aa0e597d Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Fri, 13 Aug 2021 18:56:38 +0530 Subject: [PATCH 16/39] use existing method to reset user's progress --- controllers/custom_wizard/wizard.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/custom_wizard/wizard.rb b/controllers/custom_wizard/wizard.rb index bb692ebb..7125fc8a 100644 --- a/controllers/custom_wizard/wizard.rb +++ b/controllers/custom_wizard/wizard.rb @@ -69,7 +69,7 @@ class CustomWizard::WizardController < ::ApplicationController end submission.remove if submission.present? - wizard.reset_user_progress! + wizard.reset end render json: result From 3c70b712bf5c6078e8de27becf46c270e0d3d066 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Fri, 13 Aug 2021 18:57:20 +0530 Subject: [PATCH 17/39] remove redundant reset method --- lib/custom_wizard/wizard.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/custom_wizard/wizard.rb b/lib/custom_wizard/wizard.rb index 5adfbf1a..8f5a897f 100644 --- a/lib/custom_wizard/wizard.rb +++ b/lib/custom_wizard/wizard.rb @@ -286,14 +286,6 @@ class CustomWizard::Wizard end end - def reset_user_progress! - UserHistory.where( - action: UserHistory.actions[:custom_wizard_step], - acting_user_id: user.id, - context: id - ).destroy_all - end - def final_cleanup! if id == user.custom_fields['redirect_to_wizard'] user.custom_fields.delete('redirect_to_wizard') From e260241dea5df4bff9f0803e0dba90a8a6d4fe4c Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Fri, 13 Aug 2021 18:58:33 +0530 Subject: [PATCH 18/39] group specs related to `skip` functionality in a context --- .../custom_wizard/wizard_controller_spec.rb | 79 ++++++++++--------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/spec/requests/custom_wizard/wizard_controller_spec.rb b/spec/requests/custom_wizard/wizard_controller_spec.rb index 4cd47c80..87ff7efe 100644 --- a/spec/requests/custom_wizard/wizard_controller_spec.rb +++ b/spec/requests/custom_wizard/wizard_controller_spec.rb @@ -50,52 +50,55 @@ describe CustomWizard::WizardController do expect(response.parsed_body["error"]).to eq("We couldn't find a wizard at that address.") end - it 'skips a wizard if user is allowed to skip' do - put '/w/super-mega-fun-wizard/skip.json' - expect(response.status).to eq(200) - end + context 'when user skips the wizard' do - it 'lets user skip if user cant access wizard' do - @template["permitted"] = permitted_json["permitted"] - CustomWizard::Template.save(@template, skip_jobs: true) + it 'skips a wizard if user is allowed to skip' do + put '/w/super-mega-fun-wizard/skip.json' + expect(response.status).to eq(200) + end - put '/w/super-mega-fun-wizard/skip.json' - expect(response.status).to eq(200) - end + it 'lets user skip if user cant access wizard' do + @template["permitted"] = permitted_json["permitted"] + CustomWizard::Template.save(@template, skip_jobs: true) - it 'returns a no skip message if user is not allowed to skip' do - @template['required'] = 'true' - CustomWizard::Template.save(@template) - put '/w/super-mega-fun-wizard/skip.json' - expect(response.parsed_body['error']).to eq("Wizard can't be skipped") - end + put '/w/super-mega-fun-wizard/skip.json' + expect(response.status).to eq(200) + end - it 'skip response contains a redirect_to if in users submissions' do - @wizard = CustomWizard::Wizard.create(@template["id"], user) - CustomWizard::Submission.new(@wizard, redirect_to: "/t/2").save - put '/w/super-mega-fun-wizard/skip.json' - expect(response.parsed_body['redirect_to']).to eq('/t/2') - end + it 'returns a no skip message if user is not allowed to skip' do + @template['required'] = 'true' + CustomWizard::Template.save(@template) + put '/w/super-mega-fun-wizard/skip.json' + expect(response.parsed_body['error']).to eq("Wizard can't be skipped") + end - it "deletes the submission if user has filled up some data" do - @wizard = CustomWizard::Wizard.create(@template["id"], user) - CustomWizard::Submission.new(@wizard, step_1_field_1: "Hello World").save - current_submission = @wizard.current_submission - put '/w/super-mega-fun-wizard/skip.json' - list = CustomWizard::Submission.list(@wizard) + it 'skip response contains a redirect_to if in users submissions' do + @wizard = CustomWizard::Wizard.create(@template["id"], user) + CustomWizard::Submission.new(@wizard, redirect_to: "/t/2").save + put '/w/super-mega-fun-wizard/skip.json' + expect(response.parsed_body['redirect_to']).to eq('/t/2') + end - expect(list.any? { |submission| submission.id == current_submission.id }).to eq(false) - end + it "deletes the submission if user has filled up some data" do + @wizard = CustomWizard::Wizard.create(@template["id"], user) + CustomWizard::Submission.new(@wizard, step_1_field_1: "Hello World").save + current_submission = @wizard.current_submission + put '/w/super-mega-fun-wizard/skip.json' + list = CustomWizard::Submission.list(@wizard) - it "starts from the first step if user visits after skipping the wizard" do - put '/w/super-mega-fun-wizard/steps/step_1.json', params: { - fields: { - step_1_field_1: "Text input" + expect(list.any? { |submission| submission.id == current_submission.id }).to eq(false) + end + + it "starts from the first step if user visits after skipping the wizard" do + put '/w/super-mega-fun-wizard/steps/step_1.json', params: { + fields: { + step_1_field_1: "Text input" + } } - } - put '/w/super-mega-fun-wizard/skip.json' - get '/w/super-mega-fun-wizard.json' + put '/w/super-mega-fun-wizard/skip.json' + get '/w/super-mega-fun-wizard.json' - expect(response.parsed_body["start"]).to eq('step_1') + expect(response.parsed_body["start"]).to eq('step_1') + end end end From 1916335fa901dd203587825d5c2ca1744a0b2655 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Mon, 23 Aug 2021 03:00:14 +0530 Subject: [PATCH 19/39] FIX: use class method as alias for instance method --- lib/custom_wizard/submission.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/custom_wizard/submission.rb b/lib/custom_wizard/submission.rb index de33e817..f64e90ba 100644 --- a/lib/custom_wizard/submission.rb +++ b/lib/custom_wizard/submission.rb @@ -98,20 +98,20 @@ class CustomWizard::Submission end def self.remove(submission) - if submission.present? - user_id = submission.user.id - wizard_id = submission.wizard.id - submission_id = submission.id + submission.remove + end + + def remove + if present? + user_id = @user.id + wizard_id = @wizard.id + submission_id = @id data = PluginStore.get("#{wizard_id}_#{KEY}", user_id) data.delete_if { |sub| sub["id"] == submission_id } PluginStore.set("#{wizard_id}_#{KEY}", user_id, data) end end - def remove - self.class.remove(self) - end - def self.cleanup_incomplete_submissions(wizard) user_id = wizard.user.id all_submissions = list(wizard, user_id: user_id) From 0b20c6ff81498af86f694f4e201c0a5c4f5be64e Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Mon, 23 Aug 2021 10:38:02 +0530 Subject: [PATCH 20/39] removed redundant method --- lib/custom_wizard/submission.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/custom_wizard/submission.rb b/lib/custom_wizard/submission.rb index f64e90ba..61bb008a 100644 --- a/lib/custom_wizard/submission.rb +++ b/lib/custom_wizard/submission.rb @@ -97,10 +97,6 @@ class CustomWizard::Submission new(wizard, data, user_id) end - def self.remove(submission) - submission.remove - end - def remove if present? user_id = @user.id From 03fb7b7adab3780fc0860ed8da27cc144861095c Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Wed, 25 Aug 2021 09:59:24 +0800 Subject: [PATCH 21/39] 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 22/39] 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 23/39] 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 8eced70f60935f64c9678a0175387261fd1c6c76 Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Tue, 31 Aug 2021 11:25:06 +0800 Subject: [PATCH 24/39] COMPATIBILITY: Add new composer-upload mixin --- assets/javascripts/wizard-custom.js | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/javascripts/wizard-custom.js b/assets/javascripts/wizard-custom.js index 8b30ad94..d0fef99a 100644 --- a/assets/javascripts/wizard-custom.js +++ b/assets/javascripts/wizard-custom.js @@ -2,6 +2,7 @@ //= require discourse/app/mixins/singleton //= require discourse/app/mixins/upload +//= require discourse/app/mixins/composer-upload //= require discourse/app/adapters/rest From aa928c319e8fd7da010a48c894b7535c1b41a5bb Mon Sep 17 00:00:00 2001 From: KC Maddever Date: Tue, 10 Aug 2021 20:11:41 +0800 Subject: [PATCH 25/39] DEV: add data migration to split out log fields --- ...06135416_split_custom_wizard_log_fields.rb | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 db/migrate/20210806135416_split_custom_wizard_log_fields.rb diff --git a/db/migrate/20210806135416_split_custom_wizard_log_fields.rb b/db/migrate/20210806135416_split_custom_wizard_log_fields.rb new file mode 100644 index 00000000..b261c497 --- /dev/null +++ b/db/migrate/20210806135416_split_custom_wizard_log_fields.rb @@ -0,0 +1,70 @@ +class SplitCustomWizardLogFields < ActiveRecord::Migration[6.1] + def change + reversible do |dir| + dir.up do + # separate wizard/action/user into their own keys + + wizard_logs = PluginStoreRow.where(" + plugin_name = 'custom_wizard_log' + ") + + if wizard_logs.exists? + wizard_logs.each do |row| + begin + log_json = JSON.parse(row.value) + rescue TypeError, JSON::ParserError + next + end + + # first three keys are wizard/action/user + + if log_json.key?('message') + attr_strs = log_json['message'].split('; ', 4) + + log_json['message'] = attr_strs.pop + + attr_strs.each do |attr_str| + key, value = attr_str.split(': ') + log_json[key] = value + end + + row.value = log_json.to_json + row.save + + end + end + end + end + dir.down do + wizard_logs = PluginStoreRow.where(" + plugin_name = 'custom_wizard_log' + ") + + if wizard_logs.exists? + wizard_logs.each do |row| + begin + log_json = JSON.parse(row.value) + rescue TypeError, JSON::ParserError + next + end + + # concatenate wizard/action/user to start of message + prefixes = log_json.extract!('wizard', 'action', 'user') + + message_prefix = prefixes.map{|k,v| "#{k}: #{v}"}.join('; ') + + if log_json.key?('message') + log_json['message'] = "#{message_prefix}; #{log_json['message']}" + else + log_json['message'] = message_prefix + end + + row.value = log_json.to_json + row.save + + end + end + end + end + end +end From b79039c2e2d98d89d0dee99413b52328666de0ca Mon Sep 17 00:00:00 2001 From: KC Maddever Date: Tue, 10 Aug 2021 21:18:02 +0800 Subject: [PATCH 26/39] DEV: save logs with split fields --- lib/custom_wizard/action.rb | 15 ++++++--------- lib/custom_wizard/log.rb | 12 +++++++++--- serializers/custom_wizard/log_serializer.rb | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index 1b5770d7..79094024 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -742,14 +742,11 @@ class CustomWizard::Action end def save_log - log = "wizard: #{@wizard.id}; action: #{action['type']}; user: #{user.username}" - - if @log.any? - @log.each do |item| - log += "; #{item.to_s}" - end - end - - CustomWizard::Log.create(log) + CustomWizard::Log.create( + @wizard.id, + action['type'], + user.username, + @log.join('; ') + ) end end diff --git a/lib/custom_wizard/log.rb b/lib/custom_wizard/log.rb index fc747440..c50a5712 100644 --- a/lib/custom_wizard/log.rb +++ b/lib/custom_wizard/log.rb @@ -2,22 +2,28 @@ class CustomWizard::Log include ActiveModel::Serialization - attr_accessor :message, :date + attr_accessor :date, :wizard, :action, :user, :message PAGE_LIMIT = 100 def initialize(attrs) - @message = attrs['message'] @date = attrs['date'] + @wizard = attrs['wizard'] + @action = attrs['action'] + @user = attrs['user'] + @message = attrs['message'] end - def self.create(message) + def self.create(wizard, action, user, message) log_id = SecureRandom.hex(12) PluginStore.set('custom_wizard_log', log_id.to_s, { date: Time.now, + wizard: wizard, + action: action, + user: user, message: message } ) diff --git a/serializers/custom_wizard/log_serializer.rb b/serializers/custom_wizard/log_serializer.rb index e521c573..c4683ba8 100644 --- a/serializers/custom_wizard/log_serializer.rb +++ b/serializers/custom_wizard/log_serializer.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true class CustomWizard::LogSerializer < ApplicationSerializer - attributes :message, :date + attributes :date, :wizard, :action, :user, :message end From 35ff172967eaa4964e9e919688dc090dd7a29cce Mon Sep 17 00:00:00 2001 From: KC Maddever Date: Tue, 24 Aug 2021 20:41:51 +0800 Subject: [PATCH 27/39] DEV: specify which fields to split in log data migration --- ...06135416_split_custom_wizard_log_fields.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/db/migrate/20210806135416_split_custom_wizard_log_fields.rb b/db/migrate/20210806135416_split_custom_wizard_log_fields.rb index b261c497..2e7b7d21 100644 --- a/db/migrate/20210806135416_split_custom_wizard_log_fields.rb +++ b/db/migrate/20210806135416_split_custom_wizard_log_fields.rb @@ -16,16 +16,23 @@ class SplitCustomWizardLogFields < ActiveRecord::Migration[6.1] next end - # first three keys are wizard/action/user - if log_json.key?('message') - attr_strs = log_json['message'].split('; ', 4) + if log_json.key?('message') and log_json['message'].is_a? String - log_json['message'] = attr_strs.pop + attr_strs = [] + + # assumes no whitespace in the values + attr_strs << log_json['message'].slice!(/(wizard: \S*; )/, 1) + attr_strs << log_json['message'].slice!(/(action: \S*; )/, 1) + attr_strs << log_json['message'].slice!(/(user: \S*; )/, 1) attr_strs.each do |attr_str| - key, value = attr_str.split(': ') - log_json[key] = value + if attr_str.is_a? String + attr_str.gsub!(/[;]/ ,"") + key, value = attr_str.split(': ') + value.strip! if value + log_json[key] = value ? value : '' + end end row.value = log_json.to_json From c394656ed877469a90ae86106cbcbbd82fd72751 Mon Sep 17 00:00:00 2001 From: KC Maddever Date: Mon, 30 Aug 2021 21:45:57 +0800 Subject: [PATCH 28/39] DEV: update tests for split log fields --- spec/components/custom_wizard/log_spec.rb | 6 +++--- spec/requests/custom_wizard/admin/logs_controller_spec.rb | 6 +++--- spec/serializers/custom_wizard/log_serializer_spec.rb | 7 +++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/spec/components/custom_wizard/log_spec.rb b/spec/components/custom_wizard/log_spec.rb index 30fd0173..62f2e6df 100644 --- a/spec/components/custom_wizard/log_spec.rb +++ b/spec/components/custom_wizard/log_spec.rb @@ -3,9 +3,9 @@ require_relative '../../plugin_helper' describe CustomWizard::Log do before do - CustomWizard::Log.create("First log message") - CustomWizard::Log.create("Second log message") - CustomWizard::Log.create("Third log message") + CustomWizard::Log.create('first-test-wizard', 'perform_first_action', 'first_test_user', 'First log message') + CustomWizard::Log.create('second-test-wizard', 'perform_second_action', 'second_test_user', 'Second log message') + CustomWizard::Log.create('third-test-wizard', 'perform_third_action', 'third_test_user', 'Third log message') end it "creates logs" do diff --git a/spec/requests/custom_wizard/admin/logs_controller_spec.rb b/spec/requests/custom_wizard/admin/logs_controller_spec.rb index 28b7d785..5aaf9578 100644 --- a/spec/requests/custom_wizard/admin/logs_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/logs_controller_spec.rb @@ -5,9 +5,9 @@ describe CustomWizard::AdminLogsController do fab!(:admin_user) { Fabricate(:user, admin: true) } before do - CustomWizard::Log.create("First log message") - CustomWizard::Log.create("Second log message") - CustomWizard::Log.create("Third log message") + CustomWizard::Log.create('first-test-wizard', 'perform_first_action', 'first_test_user', 'First log message') + CustomWizard::Log.create('second-test-wizard', 'perform_second_action', 'second_test_user', 'Second log message') + CustomWizard::Log.create('third-test-wizard', 'perform_third_action', 'third_test_user', 'Third log message') sign_in(admin_user) end diff --git a/spec/serializers/custom_wizard/log_serializer_spec.rb b/spec/serializers/custom_wizard/log_serializer_spec.rb index bde16199..b452b9c5 100644 --- a/spec/serializers/custom_wizard/log_serializer_spec.rb +++ b/spec/serializers/custom_wizard/log_serializer_spec.rb @@ -6,14 +6,17 @@ describe CustomWizard::LogSerializer do fab!(:user) { Fabricate(:user) } it 'should return log attributes' do - CustomWizard::Log.create("First log message") - CustomWizard::Log.create("Second log message") + CustomWizard::Log.create('first-test-wizard', 'perform_first_action', 'first_test_user', 'First log message') + CustomWizard::Log.create('second-test-wizard', 'perform_second_action', 'second_test_user', 'Second log message') json_array = ActiveModel::ArraySerializer.new( CustomWizard::Log.list(0), each_serializer: CustomWizard::LogSerializer ).as_json expect(json_array.length).to eq(2) + expect(json_array[0][:wizard]).to eq("second-test-wizard") + expect(json_array[0][:action]).to eq("perform_second_action") + expect(json_array[0][:user]).to eq("second_test_user") expect(json_array[0][:message]).to eq("Second log message") end end From 399cc9c2205fed2ebdd7b82a5ffe5d9fbe97f4cd Mon Sep 17 00:00:00 2001 From: KC Maddever Date: Tue, 31 Aug 2021 14:43:21 +0800 Subject: [PATCH 29/39] DEV: rubocop --- ...10806135416_split_custom_wizard_log_fields.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/db/migrate/20210806135416_split_custom_wizard_log_fields.rb b/db/migrate/20210806135416_split_custom_wizard_log_fields.rb index 2e7b7d21..984a7a23 100644 --- a/db/migrate/20210806135416_split_custom_wizard_log_fields.rb +++ b/db/migrate/20210806135416_split_custom_wizard_log_fields.rb @@ -1,11 +1,12 @@ +# frozen_string_literal: true class SplitCustomWizardLogFields < ActiveRecord::Migration[6.1] def change reversible do |dir| dir.up do - # separate wizard/action/user into their own keys + # separate wizard/action/user into their own keys - wizard_logs = PluginStoreRow.where(" - plugin_name = 'custom_wizard_log' + wizard_logs = PluginStoreRow.where(" + plugin_name = 'custom_wizard_log' ") if wizard_logs.exists? @@ -16,8 +17,7 @@ class SplitCustomWizardLogFields < ActiveRecord::Migration[6.1] next end - - if log_json.key?('message') and log_json['message'].is_a? String + if log_json.key?('message') && log_json['message'].is_a?(String) attr_strs = [] @@ -28,7 +28,7 @@ class SplitCustomWizardLogFields < ActiveRecord::Migration[6.1] attr_strs.each do |attr_str| if attr_str.is_a? String - attr_str.gsub!(/[;]/ ,"") + attr_str.gsub!(/[;]/ , "") key, value = attr_str.split(': ') value.strip! if value log_json[key] = value ? value : '' @@ -44,7 +44,7 @@ class SplitCustomWizardLogFields < ActiveRecord::Migration[6.1] end dir.down do wizard_logs = PluginStoreRow.where(" - plugin_name = 'custom_wizard_log' + plugin_name = 'custom_wizard_log' ") if wizard_logs.exists? @@ -58,7 +58,7 @@ class SplitCustomWizardLogFields < ActiveRecord::Migration[6.1] # concatenate wizard/action/user to start of message prefixes = log_json.extract!('wizard', 'action', 'user') - message_prefix = prefixes.map{|k,v| "#{k}: #{v}"}.join('; ') + message_prefix = prefixes.map { |k, v| "#{k}: #{v}" }.join('; ') if log_json.key?('message') log_json['message'] = "#{message_prefix}; #{log_json['message']}" From 280d2ffe54e4a9e3debe95deafa7bc419665707b Mon Sep 17 00:00:00 2001 From: Keegan George Date: Tue, 31 Aug 2021 13:29:30 -0700 Subject: [PATCH 30/39] 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 0e5fc756df74b61db0c2f5b967827c0b7a73fdfc Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Wed, 1 Sep 2021 10:46:52 +0800 Subject: [PATCH 31/39] Fix merge issues --- lib/custom_wizard/submission.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/custom_wizard/submission.rb b/lib/custom_wizard/submission.rb index 050ec000..89de50bf 100644 --- a/lib/custom_wizard/submission.rb +++ b/lib/custom_wizard/submission.rb @@ -45,7 +45,7 @@ class CustomWizard::Submission validate submission_list = self.class.list(wizard, user_id: user.id) - submissions = submission_list.select { |submission| submission.id != self.id } + submissions = submission_list.submissions.select { |submission| submission.id != self.id } self.updated_at = Time.now.iso8601 submissions.push(self) @@ -112,7 +112,7 @@ class CustomWizard::Submission def self.cleanup_incomplete_submissions(wizard) user_id = wizard.user.id all_submissions = list(wizard, user_id: user_id) - sorted_submissions = all_submissions.sort_by do |submission| + sorted_submissions = all_submissions.submissions.sort_by do |submission| zero_epoch_time = DateTime.strptime("0", '%s') [ submission.submitted_at ? Time.iso8601(submission.submitted_at) : zero_epoch_time, @@ -132,7 +132,7 @@ class CustomWizard::Submission PluginStore.set("#{wizard.id}_#{KEY}", user_id, valid_data) end - def self.list(wizard, user_id: nil, order_by: nil) + def self.list(wizard, user_id: nil, order_by: nil, page: nil) params = { plugin_name: "#{wizard.id}_#{KEY}" } params[:key] = user_id if user_id.present? From 403f063b0f1c2799df47784f8f52f68fb19f11dc Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Wed, 1 Sep 2021 11:10:49 +0800 Subject: [PATCH 32/39] Fix failing specs --- .../custom_wizard/submission_spec.rb | 69 ++++++++++--------- .../custom_wizard/wizard_controller_spec.rb | 4 +- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/spec/components/custom_wizard/submission_spec.rb b/spec/components/custom_wizard/submission_spec.rb index a9caaa0a..4e8d86c0 100644 --- a/spec/components/custom_wizard/submission_spec.rb +++ b/spec/components/custom_wizard/submission_spec.rb @@ -13,39 +13,44 @@ describe CustomWizard::Submission do before do CustomWizard::Template.save(template_json, skip_jobs: true) - - template_json_2 = template_json.dup - template_json_2["id"] = "super_mega_fun_wizard_2" - CustomWizard::Template.save(template_json_2, skip_jobs: true) - @wizard = CustomWizard::Wizard.create(template_json["id"], user) - @wizard2 = CustomWizard::Wizard.create(template_json["id"], user2) - @wizard3 = CustomWizard::Wizard.create(template_json_2["id"], user) - @count = CustomWizard::Submission::PAGE_LIMIT + 20 - - @count.times do |index| - described_class.new(@wizard, step_1_field_1: "I am user submission #{index + 1}").save - end - described_class.new(@wizard2, step_1_field_1: "I am another user's submission").save - described_class.new(@wizard3, step_1_field_1: "I am a user submission on another wizard").save + described_class.new(@wizard, step_1_field_1: "I am user submission").save end it "saves a user's submission" do expect( described_class.get(@wizard, user.id).fields["step_1_field_1"] - ).to eq("I am user submission #{@count}") + ).to eq("I am user submission") end - it "list submissions by wizard" do - expect(described_class.list(@wizard).total).to eq(@count + 1) - end + context "#list" do + before do + template_json_2 = template_json.dup + template_json_2["id"] = "super_mega_fun_wizard_2" + CustomWizard::Template.save(template_json_2, skip_jobs: true) - it "list submissions by wizard and user" do - expect(described_class.list(@wizard, user_id: user.id).total).to eq(@count) - end + @wizard2 = CustomWizard::Wizard.create(template_json["id"], user2) + @wizard3 = CustomWizard::Wizard.create(template_json_2["id"], user) + @count = CustomWizard::Submission::PAGE_LIMIT + 20 - it "paginates submission lists" do - expect(described_class.list(@wizard, page: 1).submissions.size).to eq((@count + 1) - CustomWizard::Submission::PAGE_LIMIT) + @count.times do |index| + described_class.new(@wizard, step_1_field_1: "I am user submission #{index + 1}").save + end + described_class.new(@wizard2, step_1_field_1: "I am another user's submission").save + described_class.new(@wizard3, step_1_field_1: "I am a user submission on another wizard").save + end + + it "list submissions by wizard" do + expect(described_class.list(@wizard).total).to eq(@count + 2) + end + + it "list submissions by wizard and user" do + expect(described_class.list(@wizard, user_id: user.id).total).to eq(@count + 1) + end + + it "paginates submission lists" do + expect(described_class.list(@wizard, page: 1).submissions.size).to eq((@count + 2) - CustomWizard::Submission::PAGE_LIMIT) + end end context "#cleanup_incomplete_submissions" do @@ -54,10 +59,10 @@ describe CustomWizard::Submission do described_class.new(@wizard, step_1_field_1: "I am the second submission").save builder = CustomWizard::Builder.new(@wizard.id, @wizard.user) builder.build - sub_list = described_class.list(@wizard, user_id: @wizard.user.id) + submissions = described_class.list(@wizard, user_id: @wizard.user.id).submissions - expect(sub_list.length).to eq(1) - expect(sub_list.first.fields["step_1_field_1"]).to eq("I am the second submission") + expect(submissions.length).to eq(1) + expect(submissions.first.fields["step_1_field_1"]).to eq("I am the second submission") end it "handles submissions without 'updated_at' field correctly" do @@ -70,10 +75,10 @@ describe CustomWizard::Submission do PluginStore.set("#{@wizard.id}_submissions", @wizard.user.id, sub_data) builder = CustomWizard::Builder.new(@wizard.id, @wizard.user) builder.build - sub_list = described_class.list(@wizard, user_id: @wizard.user.id) + submissions = described_class.list(@wizard, user_id: @wizard.user.id).submissions - expect(sub_list.length).to eq(1) - expect(sub_list.first.fields["step_1_field_1"]).to eq("I am the third submission") + expect(submissions.length).to eq(1) + expect(submissions.first.fields["step_1_field_1"]).to eq("I am the third submission") end it "handles submissions with and without 'updated_at' field correctly" do @@ -87,10 +92,10 @@ describe CustomWizard::Submission do builder = CustomWizard::Builder.new(@wizard.id, @wizard.user) builder.build - sub_list = described_class.list(@wizard, user_id: @wizard.user.id) + submissions = described_class.list(@wizard, user_id: @wizard.user.id).submissions - expect(sub_list.length).to eq(1) - expect(sub_list.first.fields["step_1_field_1"]).to eq("I am the third submission") + expect(submissions.length).to eq(1) + expect(submissions.first.fields["step_1_field_1"]).to eq("I am the third submission") end end end diff --git a/spec/requests/custom_wizard/wizard_controller_spec.rb b/spec/requests/custom_wizard/wizard_controller_spec.rb index 87ff7efe..26f90040 100644 --- a/spec/requests/custom_wizard/wizard_controller_spec.rb +++ b/spec/requests/custom_wizard/wizard_controller_spec.rb @@ -84,9 +84,9 @@ describe CustomWizard::WizardController do CustomWizard::Submission.new(@wizard, step_1_field_1: "Hello World").save current_submission = @wizard.current_submission put '/w/super-mega-fun-wizard/skip.json' - list = CustomWizard::Submission.list(@wizard) + submissions = CustomWizard::Submission.list(@wizard).submissions - expect(list.any? { |submission| submission.id == current_submission.id }).to eq(false) + expect(submissions.any? { |submission| submission.id == current_submission.id }).to eq(false) end it "starts from the first step if user visits after skipping the wizard" do From 7b13605c7bb51f3bd3ca351b65f7f1726b6b64d4 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Wed, 1 Sep 2021 12:46:39 -0700 Subject: [PATCH 33/39] 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 34/39] =?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 35/39] =?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 36/39] =?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 37/39] =?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 38/39] 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 39/39] 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}} +