2020-06-01 13:15:59 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { filterBy } from '@ember/object/computed';
|
2020-06-10 13:49:16 +00:00
|
|
|
import { tagName } from '@ember-decorators/component';
|
|
|
|
import classic from 'ember-classic-decorator';
|
2020-06-01 13:15:59 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
@tagName('')
|
|
|
|
export default class Browser extends Component {
|
|
|
|
model = null;
|
2020-06-01 13:15:59 +00:00
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('model.allocation')
|
2020-06-10 13:49:16 +00:00
|
|
|
get allocation() {
|
2020-06-01 13:15:59 +00:00
|
|
|
if (this.model.allocation) {
|
|
|
|
return this.model.allocation;
|
|
|
|
} else {
|
|
|
|
return this.model;
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-06-01 13:15:59 +00:00
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('model.allocation')
|
2020-06-10 13:49:16 +00:00
|
|
|
get taskState() {
|
2020-06-01 13:15:59 +00:00
|
|
|
if (this.model.allocation) {
|
|
|
|
return this.model;
|
|
|
|
}
|
2020-06-09 21:03:28 +00:00
|
|
|
|
2020-06-10 14:07:16 +00:00
|
|
|
return undefined;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-06-01 13:15:59 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('taskState')
|
|
|
|
get type() {
|
2020-06-01 19:03:56 +00:00
|
|
|
if (this.taskState) {
|
2020-06-01 13:15:59 +00:00
|
|
|
return 'task';
|
|
|
|
} else {
|
|
|
|
return 'allocation';
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-06-01 13:15:59 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@filterBy('directoryEntries', 'IsDir') directories;
|
|
|
|
@filterBy('directoryEntries', 'IsDir', false) files;
|
2020-06-01 13:15:59 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
@computed(
|
|
|
|
'directories',
|
|
|
|
'directoryEntries.[]',
|
|
|
|
'files',
|
|
|
|
'sortDescending',
|
|
|
|
'sortProperty'
|
|
|
|
)
|
2020-06-10 13:49:16 +00:00
|
|
|
get sortedDirectoryEntries() {
|
|
|
|
const sortProperty = this.sortProperty;
|
2020-06-01 13:15:59 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
const directorySortProperty =
|
|
|
|
sortProperty === 'Size' ? 'Name' : sortProperty;
|
2020-06-01 13:15:59 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
const sortedDirectories = this.directories.sortBy(directorySortProperty);
|
|
|
|
const sortedFiles = this.files.sortBy(sortProperty);
|
2020-06-01 13:15:59 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
const sortedDirectoryEntries = sortedDirectories.concat(sortedFiles);
|
2020-06-01 13:15:59 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
if (this.sortDescending) {
|
|
|
|
return sortedDirectoryEntries.reverse();
|
|
|
|
} else {
|
|
|
|
return sortedDirectoryEntries;
|
2020-06-01 13:15:59 +00:00
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|