mirror of
https://github.com/discourse/discourse-data-explorer.git
synced 2025-02-18 01:14:57 +00:00
DEV: Convert ajax functions to async (#273)
This commit is contained in:
parent
2a596e3fd9
commit
70458df7cc
@ -104,20 +104,19 @@ export default class PluginsExplorerController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
save() {
|
async save() {
|
||||||
|
try {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
await this.selectedItem.save();
|
||||||
|
|
||||||
return this.selectedItem
|
|
||||||
.save()
|
|
||||||
.then(() => {
|
|
||||||
this.dirty = false;
|
this.dirty = false;
|
||||||
this.editingName = false;
|
this.editingName = false;
|
||||||
})
|
} catch (error) {
|
||||||
.catch((x) => {
|
popupAjaxError(error);
|
||||||
popupAjaxError(x);
|
throw error;
|
||||||
throw x;
|
} finally {
|
||||||
})
|
this.loading = false;
|
||||||
.finally(() => (this.loading = false));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
@ -212,12 +211,13 @@ export default class PluginsExplorerController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
import(files) {
|
async import(files) {
|
||||||
|
try {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
const file = files[0];
|
const file = files[0];
|
||||||
this._importQuery(file)
|
const record = await this._importQuery(file);
|
||||||
.then((record) => this.addCreatedRecord(record))
|
this.addCreatedRecord(record);
|
||||||
.catch((e) => {
|
} catch (e) {
|
||||||
if (e.jqXHR) {
|
if (e.jqXHR) {
|
||||||
popupAjaxError(e);
|
popupAjaxError(e);
|
||||||
} else if (e instanceof SyntaxError) {
|
} else if (e instanceof SyntaxError) {
|
||||||
@ -229,11 +229,10 @@ export default class PluginsExplorerController extends Controller {
|
|||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
})
|
} finally {
|
||||||
.finally(() => {
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
@ -258,14 +257,12 @@ export default class PluginsExplorerController extends Controller {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
goHome() {
|
goHome() {
|
||||||
this.setProperties({
|
this.order = null;
|
||||||
order: null,
|
this.showResults = false;
|
||||||
showResults: false,
|
this.selectedQueryId = null;
|
||||||
selectedQueryId: null,
|
this.params = null;
|
||||||
params: null,
|
this.sortByProperty = "last_run_at";
|
||||||
sortByProperty: "last_run_at",
|
this.sortDescending = true;
|
||||||
sortDescending: true,
|
|
||||||
});
|
|
||||||
this.router.transitionTo({ queryParams: { id: null, params: null } });
|
this.router.transitionTo({ queryParams: { id: null, params: null } });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,29 +287,26 @@ export default class PluginsExplorerController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
create() {
|
async create() {
|
||||||
|
try {
|
||||||
const name = this.newQueryName.trim();
|
const name = this.newQueryName.trim();
|
||||||
this.setProperties({
|
this.loading = true;
|
||||||
loading: true,
|
this.showCreate = false;
|
||||||
showCreate: false,
|
const result = await this.store.createRecord("query", { name }).save();
|
||||||
});
|
this.addCreatedRecord(result.target);
|
||||||
this.store
|
} catch (error) {
|
||||||
.createRecord("query", { name })
|
popupAjaxError(error);
|
||||||
.save()
|
} finally {
|
||||||
.then((result) => this.addCreatedRecord(result.target))
|
|
||||||
.catch(popupAjaxError)
|
|
||||||
.finally(() => {
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.dirty = true;
|
this.dirty = true;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
discard() {
|
async discard() {
|
||||||
|
try {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.store
|
const result = await this.store.find("query", this.selectedItem.id);
|
||||||
.find("query", this.selectedItem.id)
|
|
||||||
.then((result) => {
|
|
||||||
this.selectedItem.setProperties(
|
this.selectedItem.setProperties(
|
||||||
result.getProperties(Query.updatePropertyNames)
|
result.getProperties(Query.updatePropertyNames)
|
||||||
);
|
);
|
||||||
@ -323,31 +317,39 @@ export default class PluginsExplorerController extends Controller {
|
|||||||
this.selectedItem.set("group_ids", []);
|
this.selectedItem.set("group_ids", []);
|
||||||
}
|
}
|
||||||
this.dirty = false;
|
this.dirty = false;
|
||||||
})
|
} catch (error) {
|
||||||
.catch(popupAjaxError)
|
popupAjaxError(error);
|
||||||
.finally(() => (this.loading = false));
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
destroyQuery() {
|
async destroyQuery() {
|
||||||
|
try {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.showResults = false;
|
this.showResults = false;
|
||||||
this.store
|
await this.store.destroyRecord("query", this.selectedItem);
|
||||||
.destroyRecord("query", this.selectedItem)
|
this.selectedItem.set("destroyed", true);
|
||||||
.then(() => this.selectedItem.set("destroyed", true))
|
} catch (error) {
|
||||||
.catch(popupAjaxError)
|
popupAjaxError(error);
|
||||||
.finally(() => (this.loading = false));
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
recover() {
|
async recover() {
|
||||||
|
try {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.showResults = true;
|
this.showResults = true;
|
||||||
this.selectedItem
|
await this.selectedItem.save();
|
||||||
.save()
|
this.selectedItem.set("destroyed", false);
|
||||||
.then(() => this.selectedItem.set("destroyed", false))
|
} catch (error) {
|
||||||
.catch(popupAjaxError)
|
popupAjaxError(error);
|
||||||
.finally(() => (this.loading = false));
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
Loading…
x
Reference in New Issue
Block a user