Skip to content

Commit

Permalink
Looks like parse can deal with a * namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Jul 9, 2022
1 parent f14d703 commit 81c1a62
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 69 deletions.
7 changes: 2 additions & 5 deletions ui/app/adapters/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ export default class JobAdapter extends WatchableNamespaceIDs {
return this.ajax(url, 'DELETE');
}

parse(spec, namespace = '*') {
const url = addToPath(
this.urlForFindAll('job'),
`/parse?namespace=${namespace}`
);
parse(spec) {
const url = addToPath(this.urlForFindAll('job'), `/parse?namespace=*`);
return this.ajax(url, 'POST', {
data: {
JobHCL: spec,
Expand Down
46 changes: 0 additions & 46 deletions ui/app/controllers/jobs/run.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,10 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import { scheduleOnce } from '@ember/runloop';
import { serialize } from 'nomad-ui/utils/qp-serialize';
import { get, set } from '@ember/object';

export default class RunController extends Controller {
@service router;
@service system;
@service store;

queryParams = [
{
qpNamespace: 'namespace',
},
];

onSubmit(id, namespace) {
this.router.transitionTo('jobs.job', `${id}@${namespace || 'default'}`);
}
@computed('qpNamespace')
get optionsNamespaces() {
const availableNamespaces = this.store
.peekAll('namespace')
.map((namespace) => ({
key: namespace.name,
label: namespace.name,
}));

availableNamespaces.unshift({
key: '*',
label: 'All (*)',
});

// Unset the namespace selection if it was server-side deleted
if (!availableNamespaces.mapBy('key').includes(this.qpNamespace)) {
scheduleOnce('actions', () => {
// eslint-disable-next-line ember/no-side-effects
set(this, 'qpNamespace', '*');
});
}

return availableNamespaces;
}

setFacetQueryParam(queryParam, selection) {
this.set(queryParam, serialize(selection));
const model = get(this, 'model');
set(
model,
'namespace',
this.store.peekAll('namespace').find((ns) => ns.id === this.qpNamespace)
);
}
}
3 changes: 1 addition & 2 deletions ui/app/models/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ export default class Job extends Model {
parse() {
const definition = this._newDefinition;
let promise;
const namespace = this.get('namespace.id');

try {
// If the definition is already JSON then it doesn't need to be parsed.
Expand All @@ -262,7 +261,7 @@ export default class Job extends Model {

promise = this.store
.adapterFor('job')
.parse(this._newDefinition, namespace)
.parse(this._newDefinition)
.then((response) => {
this.set('_newDefinitionJSON', response);
this.setIdByPayload(response);
Expand Down
16 changes: 0 additions & 16 deletions ui/app/templates/jobs/run.hbs
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
<Breadcrumb @crumb={{hash label="Run" args=(array "jobs.run")}} />
{{page-title "Run a job"}}
<section class="section">
<div class="toolbar">
<div class="toolbar-item is-right-aligned is-mobile-full-width">
<div class="button-bar">
{{#if this.system.shouldShowNamespaces}}
<SingleSelectDropdown
data-test-namespace-facet
@label="Namespace"
@options={{this.optionsNamespaces}}
@selection={{this.qpNamespace}}
@onSelect={{action this.setFacetQueryParam "qpNamespace"}}
/>
{{/if}}
</div>
</div>
</div>

<JobEditor @job={{this.model}} @context="new" @onSubmit={{action this.onSubmit}} />
</section>

0 comments on commit 81c1a62

Please sign in to comment.