11import { action , computed } from '@ember-decorators/object' ;
2- import { alias , oneWay , or } from '@ember-decorators/object/computed' ;
2+ import { alias , or } from '@ember-decorators/object/computed' ;
33import { service } from '@ember-decorators/service' ;
44import { A } from '@ember/array' ;
55import Controller from '@ember/controller' ;
6- import { task , timeout } from 'ember-concurrency' ;
6+ import { all , task , timeout } from 'ember-concurrency' ;
77import DS from 'ember-data' ;
8+ import config from 'ember-get-config' ;
9+
810import Institution from 'ember-osf-web/models/institution' ;
911import Node from 'ember-osf-web/models/node' ;
12+ import Region from 'ember-osf-web/models/region' ;
1013import User from 'ember-osf-web/models/user' ;
1114import Analytics from 'ember-osf-web/services/analytics' ;
1215import CurrentUser from 'ember-osf-web/services/current-user' ;
1316
17+ // TODO pull these from the database
18+ const {
19+ dashboard : {
20+ noteworthyNode,
21+ popularNode,
22+ } ,
23+ } = config ;
24+
1425interface QueryHasManyResponse < T > extends Array < T > {
1526 meta ?: {
1627 total ?: number ;
@@ -36,13 +47,24 @@ export default class Dashboard extends Controller {
3647 'failedLoading-noteworthy' : boolean = false ;
3748 'failedLoading-popular' : boolean = false ;
3849
39- institutions = A ( [ ] ) ;
50+ institutions : Institution [ ] = A ( [ ] ) ;
4051 nodes : QueryHasManyResponse < Node > = A ( [ ] ) ;
4152 noteworthy = A ( [ ] ) ;
4253 popular = A ( [ ] ) ;
4354
44- getInstitutions = task ( function * ( this : Dashboard ) {
45- this . set ( 'institutions' , yield this . get ( 'store' ) . findAll ( 'institution' ) ) ;
55+ setupTask = task ( function * ( this : Dashboard ) {
56+ this . set ( 'filter' , null ) ;
57+
58+ const institutions = this . store . findAll ( 'institution' ) ;
59+
60+ yield all ( [
61+ institutions ,
62+ this . get ( 'findNodes' ) . perform ( ) ,
63+ this . get ( 'getPopularAndNoteworthy' ) . perform ( popularNode , 'popular' ) ,
64+ this . get ( 'getPopularAndNoteworthy' ) . perform ( noteworthyNode , 'noteworthy' ) ,
65+ ] ) ;
66+
67+ this . set ( 'institutions' , institutions . toArray ( ) ) ;
4668 } ) . restartable ( ) ;
4769
4870 filterNodes = task ( function * ( this : Dashboard , filter : string ) {
@@ -96,30 +118,39 @@ export default class Dashboard extends Controller {
96118 return yield user . queryHasMany ( 'nodes' , { filter : { title } } ) ;
97119 } ) . restartable ( ) ;
98120
99- createNode = task ( function * ( this : Dashboard , title : string , description : string , templateFrom : Node ) {
121+ createNode = task ( function * (
122+ this : Dashboard ,
123+ title : string ,
124+ description : string ,
125+ institutions : Institution [ ] ,
126+ templateFrom ?: Node ,
127+ storageRegion ?: Region ,
128+ ) {
100129 if ( ! title ) {
101130 return ;
102131 }
103- const store = this . get ( 'store' ) ;
104- const data = {
132+ const node = this . store . createRecord ( 'node' , {
105133 category : 'project' ,
106134 description,
107135 public : false ,
108- templateFrom,
109136 title,
110- } ;
111- const node = store . createRecord ( 'node' , data ) ;
112- const institutions = this . get ( 'institutionsSelected' ) ;
137+ } ) ;
138+
139+ if ( templateFrom ) {
140+ node . set ( 'templateFrom' , templateFrom . id ) ;
141+ }
113142 if ( institutions . length ) {
114143 node . set ( 'affiliatedInstitutions' , institutions . slice ( ) ) ;
115144 }
145+ if ( storageRegion ) {
146+ node . set ( 'region' , storageRegion ) ;
147+ }
116148 yield node . save ( ) ;
117149
118150 this . set ( 'newNode' , node ) ;
119151 } ) . drop ( ) ;
120152
121153 @alias ( 'currentUser.user' ) user ! : User ;
122- @oneWay ( 'user.institutions' ) institutionsSelected ! : DS . PromiseManyArray < Institution > | Institution [ ] ;
123154
124155 @or ( 'nodes.length' , 'filter' , 'findNodes.isRunning' ) hasNodes ! : boolean ;
125156
@@ -139,27 +170,6 @@ export default class Dashboard extends Controller {
139170 this . get ( 'findNodes' ) . perform ( ) ;
140171 }
141172
142- @action
143- selectInstitution ( this : Dashboard , institution : Institution ) {
144- const selected = this . set ( 'institutionsSelected' , this . get ( 'institutionsSelected' ) . slice ( ) ) ;
145-
146- if ( selected . includes ( institution ) ) {
147- selected . removeObject ( institution ) ;
148- } else {
149- selected . pushObject ( institution ) ;
150- }
151- }
152-
153- @action
154- selectAllInstitutions ( this : Dashboard ) {
155- this . set ( 'institutionsSelected' , this . get ( 'user' ) . get ( 'institutions' ) . slice ( ) ) ;
156- }
157-
158- @action
159- removeAllInstitutions ( this : Dashboard ) {
160- this . set ( 'institutionsSelected' , A ( [ ] ) ) ;
161- }
162-
163173 @action
164174 toggleModal ( this : Dashboard ) {
165175 if ( this . get ( 'modalOpen' ) ) {
0 commit comments