3
3
*
4
4
* This is the upsertproject controller.
5
5
*/
6
- 'use strict' ;
6
+
7
7
8
8
angular . module ( 'topcoderX' ) . controller ( 'ProjectController' , [ 'currentUser' , '$scope' , '$timeout' , 'ProjectService' ,
9
9
'$rootScope' , '$state' , 'Alert' , '$uibModal' , 'Helper' , 'Tutorial' , '$window' ,
@@ -20,24 +20,28 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
20
20
title : '' ,
21
21
tcDirectId : '' ,
22
22
repoUrl : '' ,
23
+ tags : [ ] ,
23
24
copilot : currentUser . roles . indexOf ( $rootScope . appConfig . copilotRole ) > - 1 ? currentUser . handle : '' ,
24
25
rocketChatWebhook : null ,
25
26
rocketChatChannelName : null ,
26
27
archived : false ,
27
- createCopilotPayments : false
28
+ createCopilotPayments : false ,
28
29
} ;
29
30
$scope . connectProjects = [ ] ;
30
31
if ( $rootScope . project ) {
31
32
$scope . title = 'Manage a Project' ;
32
33
$scope . project = $rootScope . project ;
33
- $scope . project . tags = ! ! $rootScope . project . tags ? $rootScope . project . tags . split ( ',' ) : [ ] ;
34
+ // Switch from v4 tags to v5 tags
35
+ if ( angular . isString ( $scope . project . tags ) ) {
36
+ $scope . project . tags = [ ] ;
37
+ }
34
38
$scope . project . repoUrl = $rootScope . project . repoUrls . join ( ',' ) ;
35
39
$scope . editing = true ;
36
40
if ( $rootScope . project . tcDirectId ) {
37
41
ProjectService . getConnectProject ( $rootScope . project . tcDirectId ) . then ( function ( resp ) {
38
42
var connectProject = {
39
43
id : resp . data . id ,
40
- name : resp . data . name
44
+ name : resp . data . name ,
41
45
} ;
42
46
$scope . connectProjects . unshift ( connectProject ) ;
43
47
} ) ;
@@ -51,15 +55,14 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
51
55
$scope . loadingConnectProjects = true ;
52
56
53
57
$scope . tags = [ ] ;
54
- $scope . fetchTags = function ( ) {
55
- ProjectService . getTags ( ) . then ( function ( resp ) {
56
- const s = new Set ( resp . data . result . content . map ( function ( tag ) { return tag . name ; } ) ) ;
57
- $scope . tags = Array . from ( s ) . sort ( ) ;
58
+
59
+ $scope . searchTags = function ( searchQuery ) {
60
+ ProjectService . searchTags ( searchQuery ) . then ( function ( resp ) {
61
+ $scope . tags = resp . data ;
58
62
} ) ;
59
- }
60
- $scope . fetchTags ( ) ;
63
+ } ;
61
64
62
- $scope . fetchConnectProjects = function ( $event ) {
65
+ $scope . fetchConnectProjects = function ( $event ) {
63
66
if ( ! $event ) {
64
67
$scope . page = 1 ;
65
68
$scope . connectProjects = [ ] ;
@@ -73,20 +76,20 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
73
76
return ;
74
77
}
75
78
$scope . loadingConnectProjects = true ;
76
- ProjectService . getConnectProjects ( 20 , $scope . page ) . then ( function ( resp ) {
79
+ ProjectService . getConnectProjects ( 20 , $scope . page ) . then ( function ( resp ) {
77
80
var projects = resp . data . filter ( function ( p ) {
78
81
return $rootScope . project && $rootScope . project . tcDirectId ? p . id !== $rootScope . project . tcDirectId : true ;
79
82
} ) ;
80
83
$scope . connectProjects = $scope . connectProjects . concat ( projects ) ;
81
- } ) [ ' finally' ] ( function ( ) {
84
+ } ) . finally ( function ( ) {
82
85
$scope . loadingConnectProjects = false ;
83
86
} ) ;
84
87
} ;
85
88
$scope . fetchConnectProjects ( ) ;
86
89
87
90
// function to add labels to the current project.
88
91
$scope . addLabels = function ( ) {
89
- ProjectService . createLabel ( { projectId : $scope . project . id } ) . then ( function ( ) {
92
+ ProjectService . createLabel ( { projectId : $scope . project . id } ) . then ( function ( ) {
90
93
Alert . info ( 'Label Added Successfully' , $scope ) ;
91
94
} ) . catch ( function ( error ) {
92
95
Alert . error ( error . data . message , $scope ) ;
@@ -95,22 +98,20 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
95
98
96
99
// function to add hooks to the current project.
97
100
$scope . addHooks = function ( ) {
98
- ProjectService . createHooks ( { projectId : $scope . project . id } ) . then ( function ( result ) {
101
+ ProjectService . createHooks ( { projectId : $scope . project . id } ) . then ( function ( result ) {
99
102
if ( result && result . data . updated === true ) {
100
- Alert . info ( 'Existing Webhook Updated Successfully' , $scope ) ;
101
- }
102
- else {
103
+ Alert . info ( 'Existing Webhook Updated Successfully' , $scope ) ;
104
+ } else {
103
105
Alert . info ( 'Webhook Added Successfully' , $scope ) ;
104
106
}
105
-
106
107
} ) . catch ( function ( error ) {
107
108
Alert . error ( error . data . message , $scope ) ;
108
109
} ) ;
109
110
} ;
110
111
111
112
// function to add wiki rules to the current project
112
113
$scope . addWikiRules = function ( ) {
113
- ProjectService . addWikiRules ( { projectId : $scope . project . id } ) . then ( function ( ) {
114
+ ProjectService . addWikiRules ( { projectId : $scope . project . id } ) . then ( function ( ) {
114
115
Alert . info ( 'Wiki Rules Added Successfully' , $scope ) ;
115
116
} ) . catch ( function ( error ) {
116
117
Alert . error ( error . data . message , $scope ) ;
@@ -128,30 +129,27 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
128
129
if ( project . copilot === '' ) {
129
130
project . copilot = null ;
130
131
}
131
- // project.repoUrls = project.repoUrl.split(',');
132
- const _project = Object . assign ( { } , project ) ;
133
- delete _project . repoUrls ;
134
132
if ( $scope . editing ) {
135
133
ProjectService . update ( project ) . then ( function ( ) {
136
134
Alert . info ( 'Project Updated Successfully' , $scope ) ;
137
- setTimeout ( function ( ) {
135
+ setTimeout ( function ( ) {
138
136
$state . go ( 'app.projects' ) ;
139
137
} , 3000 ) ;
140
138
} ) . catch ( function ( error ) {
141
139
Alert . error ( error . data . message , $scope ) ;
142
- setTimeout ( function ( ) {
140
+ setTimeout ( function ( ) {
143
141
$state . go ( 'app.projects' ) ;
144
142
} , 3000 ) ;
145
143
} ) ;
146
144
} else {
147
145
ProjectService . create ( project ) . then ( function ( ) {
148
146
Alert . info ( 'Project has been added successfully, and Topcoder X issue labels, webhook, and wiki rules have been added to the repository' , $scope ) ;
149
- setTimeout ( function ( ) {
147
+ setTimeout ( function ( ) {
150
148
$state . go ( 'app.projects' ) ;
151
149
} , 3000 ) ;
152
150
} ) . catch ( function ( error ) {
153
151
Alert . error ( error . data . message , $scope ) ;
154
- setTimeout ( function ( ) {
152
+ setTimeout ( function ( ) {
155
153
$state . go ( 'app.projects' ) ;
156
154
} , 3000 ) ;
157
155
} ) ;
@@ -164,13 +162,13 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
164
162
templateUrl : 'app/upsertproject/recreate-dialog.html' ,
165
163
controller : 'RecreateDialogController' ,
166
164
resolve : {
167
- currentUser : function ( ) {
165
+ currentUser ( ) {
168
166
return currentUser ;
169
167
} ,
170
- appConfig : function ( ) {
168
+ appConfig ( ) {
171
169
return $rootScope . appConfig ;
172
170
} ,
173
- project : function ( ) {
171
+ project ( ) {
174
172
return $scope . project ;
175
173
} ,
176
174
} ,
@@ -183,27 +181,26 @@ angular.module('topcoderX').controller('ProjectController', ['currentUser', '$sc
183
181
templateUrl : 'app/upsertproject/transfer-ownership-dialog.html' ,
184
182
controller : 'TransferOwnershipDialogController' ,
185
183
resolve : {
186
- currentUser : function ( ) {
184
+ currentUser ( ) {
187
185
return currentUser ;
188
186
} ,
189
- appConfig : function ( ) {
187
+ appConfig ( ) {
190
188
return $rootScope . appConfig ;
191
189
} ,
192
- project : function ( ) {
190
+ project ( ) {
193
191
return $scope . project ;
194
192
} ,
195
193
} ,
196
194
} ) ;
197
195
} ;
198
196
199
197
if ( tutorial ) {
200
- setTimeout ( function ( ) {
201
- var dialog = {
202
- message : 'Add your first project. Fill the project name, Direct ID, Repo URL of your Gitlab/Github Repository and the copilot.' ,
203
- action : 'close'
204
- } ;
205
- Tutorial . show ( dialog , $scope ) ;
206
- } , 2500 ) ;
198
+ setTimeout ( function ( ) {
199
+ var dialog = {
200
+ message : 'Add your first project. Fill the project name, Direct ID, Repo URL of your Gitlab/Github Repository and the copilot.' ,
201
+ action : 'close' ,
202
+ } ;
203
+ Tutorial . show ( dialog , $scope ) ;
204
+ } , 2500 ) ;
207
205
}
208
-
209
206
} ] ) ;
0 commit comments