github.com/manicqin/nomad@v0.9.5/ui/app/controllers/allocations/allocation/task/fs.js (about)

     1  import Controller from '@ember/controller';
     2  import { computed } from '@ember/object';
     3  import { filterBy } from '@ember/object/computed';
     4  
     5  export default Controller.extend({
     6    queryParams: {
     7      sortProperty: 'sort',
     8      sortDescending: 'desc',
     9    },
    10  
    11    sortProperty: 'Name',
    12    sortDescending: false,
    13  
    14    path: null,
    15    task: null,
    16    directoryEntries: null,
    17    isFile: null,
    18    stat: null,
    19  
    20    directories: filterBy('directoryEntries', 'IsDir'),
    21    files: filterBy('directoryEntries', 'IsDir', false),
    22  
    23    pathWithLeadingSlash: computed('path', function() {
    24      const path = this.path;
    25  
    26      if (path.startsWith('/')) {
    27        return path;
    28      } else {
    29        return `/${path}`;
    30      }
    31    }),
    32  
    33    sortedDirectoryEntries: computed(
    34      'directoryEntries.[]',
    35      'sortProperty',
    36      'sortDescending',
    37      function() {
    38        const sortProperty = this.sortProperty;
    39  
    40        const directorySortProperty = sortProperty === 'Size' ? 'Name' : sortProperty;
    41  
    42        const sortedDirectories = this.directories.sortBy(directorySortProperty);
    43        const sortedFiles = this.files.sortBy(sortProperty);
    44  
    45        const sortedDirectoryEntries = sortedDirectories.concat(sortedFiles);
    46  
    47        if (this.sortDescending) {
    48          return sortedDirectoryEntries.reverse();
    49        } else {
    50          return sortedDirectoryEntries;
    51        }
    52      }
    53    ),
    54  });