FIX: ensures group_ids are not "" or nil (#39)

This commit is contained in:
Joffrey JAFFEUX 2019-10-16 12:43:10 +02:00 committed by GitHub
parent c58748474a
commit 4196321e41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -7,7 +7,7 @@ import {
observes observes
} from "ember-addons/ember-computed-decorators"; } from "ember-addons/ember-computed-decorators";
const NoQuery = Query.create({ name: "No queries", fake: true }); const NoQuery = Query.create({ name: "No queries", fake: true, group_ids: [] });
export default Ember.Controller.extend({ export default Ember.Controller.extend({
queryParams: { selectedQueryId: "id" }, queryParams: { selectedQueryId: "id" },
@ -45,12 +45,17 @@ export default Ember.Controller.extend({
@computed("selectedQueryId") @computed("selectedQueryId")
selectedItem(selectedQueryId) { selectedItem(selectedQueryId) {
const id = parseInt(selectedQueryId); const id = parseInt(selectedQueryId, 10);
const item = this.model.find(q => q.id === id); const item = this.model.findBy("id", id);
!isNaN(id) !isNaN(id)
? this.set("showRecentQueries", false) ? this.set("showRecentQueries", false)
: this.set("showRecentQueries", true); : this.set("showRecentQueries", true);
if (id < 0) this.set("editDisabled", true);
if (id < 0) {
this.set("editDisabled", true);
}
return item || NoQuery; return item || NoQuery;
}, },

View File

@ -658,7 +658,8 @@ SQL
[:name, :description, :sql, :created_by, :created_at, :last_run_at].each do |sym| [:name, :description, :sql, :created_by, :created_at, :last_run_at].each do |sym|
query.send("#{sym}=", h[sym].strip) if h[sym] query.send("#{sym}=", h[sym].strip) if h[sym]
end end
query.group_ids = h[:group_ids] group_ids = (h[:group_ids] == "" || !h[:group_ids]) ? [] : h[:group_ids]
query.group_ids = group_ids
query.id = h[:id].to_i if h[:id] query.id = h[:id].to_i if h[:id]
query query
end end