This repository was archived by the owner on Apr 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathsparse-node.ts
More file actions
51 lines (41 loc) · 1.82 KB
/
sparse-node.ts
File metadata and controls
51 lines (41 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { attr, belongsTo, hasMany, AsyncBelongsTo, AsyncHasMany } from '@ember-data/model';
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import ContributorModel from 'ember-osf-web/models/contributor';
import NodeModel, { NodeCategory } from 'ember-osf-web/models/node';
import OsfModel, { Permission } from './osf-model';
export default class SparseNodeModel extends OsfModel {
@attr('fixstring') title!: string;
@attr('fixstring') description!: string;
@attr('node-category') category!: NodeCategory;
@attr('date') dateCreated!: Date;
@attr('date') dateModified!: Date;
@attr('boolean') fork!: boolean;
@alias('fork') isFork!: boolean;
@attr('fixstringarray') tags!: string[];
@attr('array') currentUserPermissions!: Permission[];
@attr('boolean') currentUserIsContributor!: boolean;
@attr('boolean') public!: boolean;
@hasMany('node', { inverse: 'parent' })
children!: AsyncHasMany<NodeModel>;
@hasMany('contributor', { inverse: 'node' })
contributors!: AsyncHasMany<ContributorModel>;
@hasMany('contributor', { inverse: null })
bibliographicContributors!: AsyncHasMany<ContributorModel>;
@belongsTo('node', { inverse: 'children' })
parent!: AsyncBelongsTo<NodeModel> & NodeModel;
@belongsTo('sparse-node', { inverse: null })
root!: AsyncBelongsTo<SparseNodeModel> & SparseNodeModel;
@belongsTo('node', { inverse: null })
detail!: AsyncBelongsTo<NodeModel> & NodeModel;
@computed('id', 'root')
get isRoot() {
const rootId = (this as SparseNodeModel).belongsTo('root').id();
return !rootId || rootId === this.id;
}
}
declare module 'ember-data/types/registries/model' {
export default interface ModelRegistry {
'sparse-node': SparseNodeModel;
} // eslint-disable-line semi
}