22
33var module = angular . module ( 'supportAdminApp' ) ;
44
5- module . controller ( 'IdeasDetailController' , [ '$scope' , '$log' , 'IdeaService' , 'Alert' , '$timeout' , 'OAuth2Service' , '$uibModalInstance' , 'ideaId' , 'domain' , 'username' , 'password' , 'clientId' , 'clientSecret' , '$sce' , 'SPIGIT_API_URL' ,
6- function ( $scope , $log , IdeaService , $alert , $timeout , OAuth2Service , $modalInstance , ideaId , domain , username , password , clientId , clientSecret , $sce , SPIGIT_API_URL ) {
5+ module . controller ( 'IdeasDetailController' , [
6+ '$scope' ,
7+ '$log' ,
8+ 'IdeaService' ,
9+ 'Alert' ,
10+ '$timeout' ,
11+ 'OAuth2Service' ,
12+ '$uibModalInstance' ,
13+ 'ideaId' ,
14+ 'domain' ,
15+ 'username' ,
16+ 'password' ,
17+ 'clientId' ,
18+ 'clientSecret' ,
19+ '$sce' ,
20+ 'SPIGIT_API_URL' ,
21+ 'ProjectService' ,
22+ function ( $scope , $log , IdeaService , $alert , $timeout , OAuth2Service , $modalInstance , ideaId , domain , username , password , clientId , clientSecret , $sce , SPIGIT_API_URL , ProjectService ) {
723
8- $scope . ideaId = ideaId ;
9- $scope . domain = domain ;
10- $scope . username = username ;
11- $scope . password = password ;
12- $scope . clientId = clientId ;
13- $scope . clientSecret = clientSecret ;
24+ $scope . ideaId = ideaId ;
25+ $scope . domain = domain ;
26+ $scope . username = username ;
27+ $scope . password = password ;
28+ $scope . clientId = clientId ;
29+ $scope . clientSecret = clientSecret ;
1430
15- $scope . form = { } ;
16- $scope . isLoading = false ;
31+ $scope . form = { } ;
32+ $scope . isLoading = false ;
1733
18- $scope . load = function ( ) {
34+ $scope . load = function ( ) {
1935
20- $scope . isLoading = true ;
36+ $scope . isLoading = true ;
2137
22- // If token expired should get new token first
23- if ( OAuth2Service . checkTokenExpireTime ( ) ) {
24- OAuth2Service . refreshToken ( $scope . username , $scope . password , $scope . domain , $scope . clientId , $scope . clientSecret ) . then ( function ( data ) {
25- $scope . loadDetail ( ) ;
26- } ) . catch ( function ( error ) {
27- $alert . error ( error . message , $scope ) ;
28- $scope . isLoading = false ;
29- } ) ;
30- } else {
31- $scope . loadDetail ( ) ;
38+ // If token expired should get new token first
39+ if ( OAuth2Service . checkTokenExpireTime ( ) ) {
40+ OAuth2Service
41+ . refreshToken ( $scope . username , $scope . password , $scope . domain , $scope . clientId , $scope . clientSecret )
42+ . then ( function ( data ) {
43+ $scope . loadDetail ( ) ;
44+ } )
45+ . catch ( function ( error ) {
46+ $alert . error ( error . message , $scope ) ;
47+ $scope . isLoading = false ;
48+ } ) ;
49+ } else {
50+ $scope . loadDetail ( ) ;
51+ }
3252 }
33- }
3453
35- // get idea detail
36- $scope . loadDetail = function ( ) {
37- IdeaService . getIdeaDetail ( domain , $scope . ideaId ) . then ( function ( data ) {
38- $scope . form . title = data . title ;
39- $scope . form . content = $sce . trustAsHtml ( $scope . convertContent ( data . content ) ) ;
40- // get creator detail
41- IdeaService . getUserDetail ( domain , data . creator_id ) . then ( function ( user ) {
42- $scope . form . firstName = user . first_name ;
43- $scope . form . lastName = user . last_name ;
44- $scope . form . email = user . primary_email ;
45- $scope . isLoading = false ;
46- } ) ;
47- } ) . catch ( function ( error ) {
48- $alert . error ( error . error , $scope ) ;
49- $scope . isLoading = false ;
50- } ) ;
51- }
54+ // get idea detail
55+ $scope . loadDetail = function ( ) {
56+ IdeaService
57+ . getIdeaDetail ( domain , $scope . ideaId )
58+ . then ( function ( data ) {
59+ $scope . idea = data ;
60+ $scope . form . title = data . title ;
61+ $scope . form . content = $sce . trustAsHtml ( $scope . convertContent ( data . content ) ) ;
62+ // get creator detail
63+ IdeaService
64+ . getUserDetail ( domain , data . creator_id )
65+ . then ( function ( user ) {
66+ $scope . user = user ;
67+ $scope . form . firstName = user . first_name ;
68+ $scope . form . lastName = user . last_name ;
69+ $scope . form . email = user . primary_email ;
70+ $scope . isLoading = false ;
71+ } ) ;
72+ } )
73+ . catch ( function ( error ) {
74+ $alert . error ( error . error , $scope ) ;
75+ $scope . isLoading = false ;
76+ } ) ;
77+ }
5278
5379 /**
5480 * Convert detail content without html tags
5581 * @param content
5682 * @returns {string }
5783 */
58- $scope . convertContent = function ( content ) {
59- var newContent = content . replace ( / < i m g [ ^ > ] * s r c = [ ' " ] ( [ ^ ' " ] + ) [ ^ > ] * > / gi, function ( match , capture ) {
60- var newStr = '<img src="http://' + domain + "." + SPIGIT_API_URL + capture + '" />' ;
61- return newStr ;
62- } ) ;
63- return newContent ;
64- }
84+ $scope . convertContent = function ( content ) {
85+ var newContent = content . replace ( / < i m g [ ^ > ] * s r c = [ ' " ] ( [ ^ ' " ] + ) [ ^ > ] * > / gi, function ( match , capture ) {
86+ var newStr = '<img src="http://' + domain + "." + SPIGIT_API_URL + capture + '" />' ;
87+ return newStr ;
88+ } ) ;
89+ return newContent ;
90+ }
6591
66- $scope . cancel = function ( ) {
92+ $scope . cancel = function ( ) {
6793 $modalInstance . close ( ) ;
6894 } ;
6995
96+ /**
97+ * Creates a project in connect using the idea details
98+ * @param content
99+ */
100+ $scope . createProject = function ( ) {
101+ var project = {
102+ name : $scope . idea . title ,
103+ description : $scope . idea . content
104+ } ;
105+ $scope . isLoading = true ;
106+ ProjectService
107+ . createProject ( project , $scope . user )
108+ . then ( function ( project ) {
109+ ProjectService
110+ . addUserToProject ( project . id , $scope . idea . creator_id )
111+ . then ( function ( data ) {
112+ $alert . info ( "Project created." , $scope ) ;
113+ } )
114+ . catch ( function ( error ) {
115+ $alert . error ( error . error , $scope ) ;
116+ } ) . finally ( function ( ) {
117+ $scope . isLoading = false ;
118+ } ) ;
119+ } )
120+ . catch ( function ( error ) {
121+ $alert . error ( error . error , $scope ) ;
122+ } ) . finally ( function ( ) {
123+ $scope . isLoading = false ;
124+ } ) ;
125+ }
70126
71- $scope . load ( ) ;
127+ $scope . load ( ) ;
72128 }
73129] ) ;
0 commit comments