open-nomad/ui/app/routes/variables/new.js
2023-04-10 15:36:59 +00:00

27 lines
712 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Route from '@ember/routing/route';
export default class VariablesNewRoute extends Route {
async model(params) {
const namespaces = await this.store.peekAll('namespace');
return this.store.createRecord('variable', {
path: params.path,
namespace: namespaces.objectAt(0)?.id,
});
}
resetController(controller, isExiting) {
// If the user navigates away from /new, clear the path
controller.set('path', null);
if (isExiting) {
// If user didn't save, delete the freshly created model
if (controller.model.isNew) {
controller.model.destroyRecord();
}
}
}
}