FIX: pagination and submitted_at ordering of submissions
Dieser Commit ist enthalten in:
Ursprung
60abb6981e
Commit
c2e759b1c5
8 geänderte Dateien mit 63 neuen und 46 gelöschten Zeilen
|
@ -25,9 +25,9 @@ export default Component.extend({
|
|||
textState: "text-collapsed",
|
||||
toggleText: I18n.t("admin.wizard.expand_text"),
|
||||
|
||||
@discourseComputed("value", "isUser")
|
||||
hasValue(value, isUser) {
|
||||
if (isUser) {
|
||||
@discourseComputed("value", "isUser", "isSubmittedAt")
|
||||
hasValue(value, isUser, isSubmittedAt) {
|
||||
if (isUser || isSubmittedAt) {
|
||||
return value;
|
||||
}
|
||||
return value && value.value;
|
||||
|
|
|
@ -3,7 +3,8 @@ 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";
|
||||
import CustomWizardAdmin from "../models/custom-wizard-admin";
|
||||
import { formatModel } from "../lib/wizard-submission";
|
||||
|
||||
export default Controller.extend({
|
||||
downloadUrl: fmt("wizard.id", "/admin/wizards/submissions/%@/download"),
|
||||
|
@ -16,10 +17,12 @@ export default Controller.extend({
|
|||
const wizardId = this.get("wizard.id");
|
||||
|
||||
this.set("loadingMore", true);
|
||||
CustomWizard.submissions(wizardId, page)
|
||||
CustomWizardAdmin.submissions(wizardId, page)
|
||||
.then((result) => {
|
||||
if (result.submissions) {
|
||||
this.get("submissions").pushObjects(result.submissions);
|
||||
const { fields, submissions } = formatModel(result);
|
||||
|
||||
this.get("submissions").pushObjects(submissions);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
|
@ -27,7 +30,7 @@ export default Controller.extend({
|
|||
});
|
||||
},
|
||||
|
||||
@discourseComputed("submissions", "fields.@each.enabled")
|
||||
@discourseComputed("submissions.[]", "fields.@each.enabled")
|
||||
displaySubmissions(submissions, fields) {
|
||||
let result = [];
|
||||
|
||||
|
|
37
assets/javascripts/discourse/lib/wizard-submission.js.es6
Normale Datei
37
assets/javascripts/discourse/lib/wizard-submission.js.es6
Normale Datei
|
@ -0,0 +1,37 @@
|
|||
import EmberObject from "@ember/object";
|
||||
|
||||
function formatModel(model) {
|
||||
let fields = [
|
||||
EmberObject.create({ id: "submitted_at", label: "Submitted At", enabled: true }),
|
||||
EmberObject.create({ id: "username", label: "User", enabled: true }),
|
||||
];
|
||||
let submissions = [];
|
||||
|
||||
model.submissions.forEach((s) => {
|
||||
let submission = {
|
||||
submitted_at: s.submitted_at,
|
||||
username: s.user,
|
||||
};
|
||||
|
||||
Object.keys(s.fields).forEach((fieldId) => {
|
||||
if (!fields.some((field) => field.id === fieldId)) {
|
||||
fields.push(
|
||||
EmberObject.create({
|
||||
id: fieldId,
|
||||
label: s.fields[fieldId].label,
|
||||
enabled: true,
|
||||
})
|
||||
);
|
||||
}
|
||||
submission[fieldId] = s.fields[fieldId];
|
||||
});
|
||||
|
||||
submissions.push(EmberObject.create(submission));
|
||||
});
|
||||
|
||||
return { fields, submissions };
|
||||
}
|
||||
|
||||
export {
|
||||
formatModel
|
||||
}
|
|
@ -211,9 +211,12 @@ CustomWizardAdmin.reopenClass({
|
|||
.catch(popupAjaxError);
|
||||
},
|
||||
|
||||
submissions(wizardId) {
|
||||
submissions(wizardId, page = 0) {
|
||||
return ajax(`/admin/wizards/submissions/${wizardId}`, {
|
||||
type: "GET",
|
||||
data: {
|
||||
page
|
||||
}
|
||||
}).catch(popupAjaxError);
|
||||
},
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { A } from "@ember/array";
|
||||
import EmberObject from "@ember/object";
|
||||
import CustomWizardAdmin from "../models/custom-wizard-admin";
|
||||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import { formatModel } from "../lib/wizard-submission";
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
model(params) {
|
||||
|
@ -9,40 +9,7 @@ export default DiscourseRoute.extend({
|
|||
},
|
||||
|
||||
setupController(controller, model) {
|
||||
let fields = [
|
||||
EmberObject.create({ id: "username", label: "User", enabled: true }),
|
||||
];
|
||||
let submissions = [];
|
||||
|
||||
model.submissions.forEach((s) => {
|
||||
let submission = {
|
||||
username: s.user,
|
||||
};
|
||||
|
||||
Object.keys(s.fields).forEach((fieldId) => {
|
||||
if (!fields.some((field) => field.id === fieldId)) {
|
||||
fields.push(
|
||||
EmberObject.create({
|
||||
id: fieldId,
|
||||
label: s.fields[fieldId].label,
|
||||
enabled: true,
|
||||
})
|
||||
);
|
||||
}
|
||||
submission[fieldId] = s.fields[fieldId];
|
||||
});
|
||||
|
||||
submission["submitted_at"] = s.submitted_at;
|
||||
submissions.push(EmberObject.create(submission));
|
||||
});
|
||||
|
||||
let submittedAt = {
|
||||
id: "submitted_at",
|
||||
label: "Submitted At",
|
||||
enabled: true,
|
||||
};
|
||||
|
||||
fields.push(EmberObject.create(submittedAt));
|
||||
const { fields, submissions } = formatModel(model);
|
||||
|
||||
controller.setProperties({
|
||||
wizard: model.wizard,
|
||||
|
|
|
@ -152,8 +152,8 @@
|
|||
{{/if}}
|
||||
|
||||
{{#if isSubmittedAt}}
|
||||
<span class="date" title={{value.value}}>
|
||||
{{d-icon "clock"}}{{format-date value format="tiny"}}
|
||||
<span class="date" title={{value}}>
|
||||
{{raw-date value}}
|
||||
</span>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
|
|
|
@ -148,6 +148,7 @@ class CustomWizard::Submission
|
|||
end
|
||||
|
||||
result.total = result.submissions.size
|
||||
result.submissions.sort_by! { |h| [h.submitted_at ? 1 : 0, h.submitted_at] }.reverse!
|
||||
|
||||
if !page.nil?
|
||||
start = page * PAGE_LIMIT
|
||||
|
|
|
@ -19,6 +19,8 @@ describe CustomWizard::Submission do
|
|||
|
||||
describe "#list" do
|
||||
before do
|
||||
freeze_time Time.now
|
||||
|
||||
template_json_2 = template_json.dup
|
||||
template_json_2["id"] = "super_mega_fun_wizard_2"
|
||||
CustomWizard::Template.save(template_json_2, skip_jobs: true)
|
||||
|
@ -28,7 +30,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}", submitted_at: Time.now + (index + 1).minutes).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
|
||||
|
@ -45,6 +47,10 @@ describe CustomWizard::Submission do
|
|||
it "paginates submission lists" do
|
||||
expect(described_class.list(@wizard, page: 1).submissions.size).to eq((@count + 2) - CustomWizard::Submission::PAGE_LIMIT)
|
||||
end
|
||||
|
||||
it "orders submissions by submitted_at" do
|
||||
expect(described_class.list(@wizard).submissions.first.submitted_at.to_datetime.change(usec: 0)).to eq((Time.now + @count.minutes).change(usec: 0))
|
||||
end
|
||||
end
|
||||
|
||||
describe "#cleanup_incomplete_submissions" do
|
||||
|
|
Laden …
In neuem Issue referenzieren