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..5ebc0ccd --- /dev/null +++ b/assets/javascripts/discourse/components/submission-field.js.es6 @@ -0,0 +1,112 @@ +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"), + 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"); + + 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/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/controllers/admin-wizards-submissions-columns.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 new file mode 100644 index 00000000..4af487ee --- /dev/null +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions-columns.js.es6 @@ -0,0 +1,15 @@ +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); + }); + }, + }, +}); 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..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,6 +1,65 @@ import Controller from "@ember/controller"; +import { empty } from "@ember/object/computed"; +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"), + 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); + }); + }, + + @discourseComputed("submissions", "fields.@each.enabled") + displaySubmissions(submissions, fields) { + 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: { + loadMore() { + if (!this.loadingMore && this.submissions.length < this.total) { + this.set("page", this.get("page") + 1); + this.loadMoreSubmissions(); + } + }, + + showEditColumnsModal() { + return showModal("admin-wizards-submissions-columns", { + model: { + fields: this.get("fields"), + submissions: this.get("submissions"), + }, + }); + }, + }, }); 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..7388a8d6 --- /dev/null +++ b/assets/javascripts/discourse/controllers/admin-wizards-submissions.js.es6 @@ -0,0 +1,34 @@ +import Controller from "@ember/controller"; +import { default as discourseComputed } from "discourse-common/utils/decorators"; + +export default Controller.extend({ + 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/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index 80c4d86a..301354e9 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) { @@ -211,10 +211,55 @@ 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", - }).catch(popupAjaxError); + data, + }) + .then((result) => { + if (result.wizard) { + let fields = [{ id: "username", label: "User" }]; + let submissions = []; + let wizard = result.wizard; + let total = result.total; + + result.submissions.forEach((s) => { + let submission = { + username: s.user, + }; + + 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); + }); + + let submittedAt = { + id: "submitted_at", + label: "Submitted At", + }; + + fields.push(submittedAt); + + 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 73168ff3..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,7 +1,7 @@ -import CustomWizard from "../models/custom-wizard"; +import { A } from "@ember/array"; +import EmberObject from "@ember/object"; import DiscourseRoute from "discourse/routes/discourse"; - -const excludedMetaFields = ["route_to", "redirect_on_complete", "redirect_to"]; +import CustomWizard from "../models/custom-wizard"; export default DiscourseRoute.extend({ model(params) { @@ -9,34 +9,16 @@ 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, - }); - } + const fields = model.fields.map((f) => { + const fieldsObject = EmberObject.create(f); + fieldsObject.enabled = true; + return fieldsObject; + }); + controller.setProperties({ + wizard: model.wizard, + fields: A(fields), + submissions: A(model.submissions), + total: model.total, + }); }, }); diff --git a/assets/javascripts/discourse/templates/admin-wizards-logs.hbs b/assets/javascripts/discourse/templates/admin-wizards-logs.hbs index b0dd3de6..ea0afb7c 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/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs b/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs index 6d1f255b..6f4996f6 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-submissions-show.hbs @@ -1,8 +1,24 @@ {{#if submissions}}{{f}} | - {{/each}} -
---|
{{v}} | - {{/each-in}} -
+ {{i18n "search.no_results"}} +
+ {{else}} ++ {{field.label}} + | + {{/if}} + {{/each}} +
---|
+ {{submission-field fieldName=field value=value}} + | + {{/each-in}} +
+ {{value.value}} +
+ + {{toggleText}} + ++ {{value.value}} +
+ + {{toggleText}} + +