|
| 1 | +import { computed } from '@ember/object'; |
| 2 | +import DS from 'ember-data'; |
| 3 | + |
| 4 | +import OsfModel from './osf-model'; |
| 5 | + |
| 6 | +const { attr } = DS; |
| 7 | + |
| 8 | +export enum StorageStatus { |
| 9 | + DEFAULT = 'DEFAULT', |
| 10 | + APPROACHING_PRIVATE = 'APPROACHING_PRIVATE', |
| 11 | + OVER_PRIVATE = 'OVER_PRIVATE', |
| 12 | + APPROACHING_PUBLIC = 'APPROACHING_PUBLIC', |
| 13 | + OVER_PUBLIC = 'OVER_PUBLIC', |
| 14 | + NOT_CALCULATED = 'NOT_CALCULATED', |
| 15 | +} |
| 16 | + |
| 17 | +export default class NodeStorageModel extends OsfModel { |
| 18 | + @attr('string') storageLimitStatus!: StorageStatus; |
| 19 | + @attr('number') storageUsage!: number; |
| 20 | + |
| 21 | + @computed('id', 'storageLimitStatus') |
| 22 | + get isOverStorageCap() { |
| 23 | + const node = this.store.peekRecord('node', this.id); |
| 24 | + if (node) { |
| 25 | + const status = this.storageLimitStatus; |
| 26 | + if (status === StorageStatus.OVER_PUBLIC) { |
| 27 | + return true; |
| 28 | + } |
| 29 | + if (!node.public) { |
| 30 | + if ([StorageStatus.OVER_PRIVATE, StorageStatus.APPROACHING_PUBLIC].includes(status)) { |
| 31 | + return true; |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + return false; |
| 36 | + } |
| 37 | + |
| 38 | + @computed('id', 'storageLimitStatus') |
| 39 | + get isApproachingStorageCap() { |
| 40 | + const node = this.store.peekRecord('node', this.id); |
| 41 | + if (node) { |
| 42 | + if (!node.public && (this.storageLimitStatus === StorageStatus.APPROACHING_PRIVATE)) { |
| 43 | + return true; |
| 44 | + } |
| 45 | + if (node.public && (this.storageLimitStatus === StorageStatus.APPROACHING_PUBLIC)) { |
| 46 | + return true; |
| 47 | + } |
| 48 | + } |
| 49 | + return false; |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +declare module 'ember-data/types/registries/model' { |
| 54 | + export default interface ModelRegistry { |
| 55 | + 'node-storage': NodeStorageModel; |
| 56 | + } // eslint-disable-line semi |
| 57 | +} |
0 commit comments