Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 8a0676c

Browse files
committed
Merge pull request #26 from appirio-tech/DEM-1193
DEM-1193 Visuals Controller
2 parents 9a3b5c4 + fca6199 commit 8a0676c

File tree

3 files changed

+214
-195
lines changed

3 files changed

+214
-195
lines changed
Lines changed: 149 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,153 @@
11
'use strict'
22

3-
SubmitWorkVisualController = ($scope, SubmitWorkAPIService, API_URL) ->
4-
vm = this
5-
vm.loading = true
6-
vm.workId = $scope.workId
3+
SubmitWorkVisualController = ($scope, $rootScope, $state, SubmitWorkService, Optimist, API_URL) ->
4+
vm = this
5+
vm.workId = $scope.workId
6+
vm.loading = true
77
vm.visualsUploaderUploading = null
88
vm.visualsUploaderHasErrors = null
9-
10-
vm.work =
11-
name : null
12-
requestType: null
13-
summary : null
14-
features : []
15-
featuresDetails : null
16-
17-
vm.visualDesign = {}
18-
vm.visualDesign.fonts = [
9+
vm.showPaths = true
10+
vm.showChooseStylesModal = false
11+
vm.showUploadStylesModal = false
12+
vm.showUrlStylesModal = false
13+
vm.activeStyleModal = null
14+
vm.nextButtonDisabled = false
15+
vm.backButtonDisabled = false
16+
vm.styleModals = ['fonts', 'colors', 'icons']
17+
18+
config = {}
19+
config.fonts = [
1920
name: 'Serif'
20-
description: 'a small line attached to the end of a stroke'
21-
id: '1234'
21+
description: 'Classic design, good legiblity for large and small text.'
22+
id: '123'
23+
selected: false
2224
,
2325
name: 'Sans Serif'
24-
description: 'does not have the small `serifs`'
25-
id: '1235'
26-
,
27-
name: 'Slap Serif'
28-
description: 'does not have the small `serifs`'
29-
id: '1236'
30-
,
31-
name: 'Script'
32-
description: 'does not have the small `serifs`'
33-
id: '1237'
34-
,
35-
name: 'Grunge'
36-
description: 'does not have the small `serifs`'
37-
id: '1238'
26+
id: '456'
27+
description: 'Modern design, good for headers and body text.'
28+
selected: false
3829
]
3930

40-
vm.visualDesign.colors = [
31+
config.colors = [
4132
name: 'Palette 1'
4233
description: 'Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
4334
id: '1234'
35+
selected: false
4436
,
4537
name: 'Palette 2'
4638
description: 'Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
4739
id: '1235'
40+
selected: false
41+
4842
,
4943
name: 'Palette 3'
5044
description: 'Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
5145
id: '1236'
46+
selected: false
47+
5248
,
5349
name: 'Palette 4'
5450
description: 'Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
5551
id: '1237'
56-
,
57-
name: 'Palette 5'
58-
description: 'Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
59-
id: '1238'
52+
selected: false
6053
]
6154

62-
vm.visualDesign.icons = [
63-
name: 'Google'
55+
config.icons = [
56+
name: 'Flat Colors'
6457
description: 'Lorem ipsum dolor sit amet'
6558
id: '1234'
59+
selected: false
60+
6661
,
67-
name: 'Anamorphic'
62+
name: 'Thin Line'
6863
description: 'Lorem ipsum dolor sit amet'
6964
id: '1235'
65+
selected: false
66+
7067
,
71-
name: 'iOS Style'
68+
name: 'Solid Line'
7269
description: 'Lorem ipsum dolor sit amet'
7370
id: '1236'
74-
,
75-
name: 'Android'
76-
description: 'Lorem ipsum dolor sit amet'
77-
id: '1237'
78-
,
79-
name: 'Windows 8'
80-
description: 'Lorem ipsum dolor sit amet'
81-
id: '1238'
71+
selected: false
8272
]
8373

84-
vm.save = (onSuccess) ->
85-
if vm.workId
86-
params =
87-
id: vm.workId
88-
89-
resource = SubmitWorkAPIService.put params, vm.work
90-
resource.$promise.then (response) ->
91-
onSuccess? response
92-
resource.$promise.catch (response) ->
93-
# TODO: add error handling
94-
95-
vm.submitVisuals = ->
96-
workFonts = vm.work.visualDesign.fonts
97-
workColors = vm.work.visualDesign.colors
98-
workIcons = vm.work.visualDesign.icons
74+
vm.showChooseStyles = ->
75+
vm.showPaths = false
76+
vm.showChooseStylesModal = true
77+
vm.backButtonDisabled = true
78+
vm.activateModal('fonts')
79+
80+
vm.showUploadStyles = ->
81+
vm.showUploadStylesModal = true
82+
83+
vm.showUrlStyles = ->
84+
vm.showUrlStylesModal = true
85+
86+
vm.activateModal = (modal) ->
87+
vm.activeStyleModal = modal
88+
updateButtons()
89+
90+
vm.viewNext = ->
91+
currentIndex = vm.styleModals.indexOf vm.activeStyleModal
92+
isValid = currentIndex < vm.styleModals.length - 1
93+
if isValid
94+
nextModal = vm.styleModals[currentIndex + 1]
95+
vm.activateModal(nextModal)
96+
97+
vm.viewPrevious = ->
98+
currentIndex = vm.styleModals.indexOf vm.activeStyleModal
99+
isValid = currentIndex > 0
100+
if isValid
101+
previousModal = vm.styleModals[currentIndex - 1]
102+
vm.activateModal(previousModal)
103+
104+
vm.save = ->
105+
visualsValid = visualDesignValid()
106+
updates = getUpdates()
107+
if visualsValid
108+
SubmitWorkService.save(updates).then ->
109+
$state.go("submit-work-development")
110+
111+
visualDesignValid = ->
112+
updates = getUpdates()
99113
uploaderValid = !vm.visualsUploaderUploading && !vm.visualsUploaderHasErrors
114+
# TODO: add updates.colors check
115+
hasVisualChoices = updates.font && updates.icons
116+
# check if visuals are selected or entered via url
117+
hasVisuals = hasVisualChoices || updates.url
118+
hasVisuals
119+
120+
getUpdates = ->
121+
updates =
122+
font: vm.work.font
123+
colors: vm.work.colors
124+
icons: vm.work.icons
125+
url: null
126+
127+
if vm.work.url
128+
updates.url = vm.visualDesign.url
129+
130+
updates
131+
132+
vm.navigateDevelopment = ->
133+
visualsValid = visualsValid()
134+
if visualsValid
135+
$state.go("submit-work-development")
136+
137+
updateButtons = ->
138+
currentIndex = vm.styleModals.indexOf vm.activeStyleModal
139+
isFirst = currentIndex == 0
140+
isLast = currentIndex == vm.styleModals.length - 1
141+
if isFirst
142+
vm.backButtonDisabled = true
143+
else if isLast
144+
vm.nextButtonDisabled = true
145+
vm.showFinishDesignButton = true
146+
else
147+
vm.nextButtonDisabled = false
148+
vm.backButtonDisabled = false
149+
vm.showFinishDesignButton = false
100150

101-
if workFonts.length && workColors.length && workIcons.length
102-
# TODO: replace with proper status
103-
vm.work.status = 'visualsAdded'
104-
vm.save (response) ->
105-
# TODO: navigate to "development" view
106-
107-
mockify = (work) ->
108-
work.visualDesign = {}
109-
work.visualDesign.fonts = []
110-
work.visualDesign.colors = []
111-
work.visualDesign.icons = []
112151

113152
configureUploader = ->
114153
assetType = 'specs'
@@ -123,31 +162,51 @@ SubmitWorkVisualController = ($scope, SubmitWorkAPIService, API_URL) ->
123162
workId: vm.workId
124163
assetType: assetType
125164

126-
activate = ->
127-
configureUploader()
128-
if vm.workId
129-
params =
130-
id: vm.workId
165+
onChange = ->
166+
if SubmitWorkService.work.o.hasPending
167+
return false
168+
169+
vm.loading = false
170+
171+
# TODO: Remove mock data once visualDesign is in payload
172+
SubmitWorkService.work.visualDesign = {}
173+
SubmitWorkService.work.visualDesign.url = null
174+
SubmitWorkService.work.visualDesign.font =
175+
id: '123'
176+
SubmitWorkService.work.visualDesign.colors =
177+
id: '1236'
178+
SubmitWorkService.work.visualDesign.icons =
179+
id: '1234'
180+
# initialize vm
181+
unless vm.visualDesign
182+
vm.visualDesign = config
183+
vm.visualDesign.fonts = config.fonts
184+
vm.visualDesign.colors = config.colors
185+
vm.visualDesign.icons = config.icons
186+
187+
vm.work = {}
188+
vm.work.icons = SubmitWorkService.work.visualDesign.icons
189+
vm.work.colors = SubmitWorkService.work.visualDesign.colors
190+
vm.work.font = SubmitWorkService.work.visualDesign.font
191+
vm.work.url = null
131192

132-
resource = SubmitWorkAPIService.get params
133193

134-
resource.$promise.then (response) ->
135-
vm.work = response
136-
#TODO: remove once all properties are in payload
137-
mockify vm.work
194+
activate = ->
195+
destroyWorkListener = $rootScope.$on "SubmitWorkService.work:changed", ->
196+
onChange()
138197

139-
resource.$promise.catch (response) ->
140-
# TODO: add error handling
198+
$scope.$on '$destroy', ->
199+
destroyWorkListener()
141200

142-
resource.$promise.finally ->
143-
vm.loading = false
144-
else
145-
vm.loading = false
201+
SubmitWorkService.fetch(vm.workId)
202+
configureUploader()
203+
# TODO: remove once work gets fetched
204+
onChange()
146205

147206
vm
148207

149208
activate()
150209

151-
SubmitWorkVisualController.$inject = ['$scope', 'SubmitWorkAPIService', 'API_URL']
210+
SubmitWorkVisualController.$inject = ['$scope', '$rootScope', '$state', 'SubmitWorkService', 'Optimist', 'API_URL']
152211

153212
angular.module('appirio-tech-ng-submit-work').controller 'SubmitWorkVisualController', SubmitWorkVisualController

0 commit comments

Comments
 (0)