open-nomad/ui/app/components/fs/browser.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.5 KiB
JavaScript
Raw Normal View History

import Component from '@ember/component';
import { computed } from '@ember/object';
import { filterBy } from '@ember/object/computed';
import { tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
@classic
@tagName('')
export default class Browser extends Component {
model = null;
@computed('model.allocation')
get allocation() {
if (this.model.allocation) {
return this.model.allocation;
} else {
return this.model;
}
}
@computed('model.allocation')
get taskState() {
if (this.model.allocation) {
return this.model;
}
return undefined;
}
@computed('taskState')
get type() {
if (this.taskState) {
return 'task';
} else {
return 'allocation';
}
}
@filterBy('directoryEntries', 'IsDir') directories;
@filterBy('directoryEntries', 'IsDir', false) files;
2021-12-28 16:08:12 +00:00
@computed(
'directories',
'directoryEntries.[]',
'files',
'sortDescending',
'sortProperty'
)
get sortedDirectoryEntries() {
const sortProperty = this.sortProperty;
2021-12-28 16:08:12 +00:00
const directorySortProperty =
sortProperty === 'Size' ? 'Name' : sortProperty;
const sortedDirectories = this.directories.sortBy(directorySortProperty);
const sortedFiles = this.files.sortBy(sortProperty);
const sortedDirectoryEntries = sortedDirectories.concat(sortedFiles);
if (this.sortDescending) {
return sortedDirectoryEntries.reverse();
} else {
return sortedDirectoryEntries;
}
}
}