Files
threshold-ui/ui/admin/app/routes/scopes/scope/targets/new.js
T
hashicorp-copywrite[bot]andCameron Perera 3d610427d0 [COMPLIANCE] Add Copyright and License Headers (#1617)
* [COMPLIANCE] Add Copyright and License Headers

* chore: 🤖 update Copyright headers to satisfy our lint rules

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
2023-03-01 09:39:41 -06:00

66 lines
1.5 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Route from '@ember/routing/route';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { TYPE_TARGET_TCP, TYPE_TARGET_SSH } from 'api/models/target';
export default class ScopesScopeTargetsNewRoute extends Route {
// =services
@service store;
@service router;
@service features;
// =methods
// =attributes
queryParams = {
type: {
refreshModel: true,
},
};
/**
* Creates a new unsaved target in current scope.
* Also rollback/destroy any new, unsaved instances from this route before
* creating another, but reuse name/description if available.
* @return {TargetModel}
*/
model({ type }) {
let name, description;
const scopeModel = this.modelFor('scopes.scope');
// default type is SSH if the feature is enabled, otherwise TCP
if (!type)
type = this.features.isEnabled('ssh-target')
? TYPE_TARGET_SSH
: TYPE_TARGET_TCP;
if (this.currentModel?.isNew) {
({ name, description } = this.currentModel);
this.currentModel.rollbackAttributes();
}
const record = this.store.createRecord('target', {
type,
name,
description,
});
record.scopeModel = scopeModel;
return record;
}
/**
* Update type of target
* @param {string} type
*/
@action
changeType(type) {
this.router.replaceWith({ queryParams: { type } });
}
}