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

Commit fca6199

Browse files
committed
Merge branch 'master' into DEM-1193
2 parents 0f977d5 + 9a3b5c4 commit fca6199

File tree

4 files changed

+144
-122
lines changed

4 files changed

+144
-122
lines changed

example/js-files.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
- scripts.push('submit-work.module')
99
- scripts.push('templates')
10-
- scripts.push('optimist')
10+
- scripts.push('services/optimist')
1111

1212
- services.push('submit-work')
1313

Lines changed: 110 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,48 @@
11
'use strict'
22

3-
SubmitWorkFeaturesController = ($scope, SubmitWorkAPIService, API_URL) ->
4-
vm = this
5-
vm.workId = $scope.workId
6-
vm.loading = true
7-
vm.showFeaturesModal = false
8-
vm.showUploadModal = false
9-
vm.showDefineFeaturesForm = false
10-
vm.activeFeature = null
3+
SubmitWorkFeaturesController = ($scope, $rootScope, SubmitWorkService, SubmitWorkAPIService, API_URL) ->
4+
vm = this
5+
vm.workId = $scope.workId
6+
vm.loading = true
7+
vm.showFeaturesModal = false
8+
vm.showUploadModal = false
9+
vm.showDefineFeaturesForm = false
10+
vm.activeFeature = null
1111
vm.featuresUploaderUploading = null
1212
vm.featuresUploaderHasErrors = null
13-
14-
vm.work =
15-
name : null
16-
requestType: null
17-
summary : null
18-
features : []
19-
featuresDetails: null
20-
21-
#TODO: replace palceholder features & descriptions
22-
vm.defaultFeatures = [
23-
name: 'Login',
24-
description: 'Users can login / register for your app',
25-
notes: null,
26-
custom: null
27-
,
28-
name: 'Onboarding',
29-
description: 'Users can see data from social networks (FB, Twitter etc.) in your app',
30-
notes: null,
31-
custom: null
32-
,
33-
name: 'Registration',
34-
description: 'Users can create profiles with personal info',
35-
notes: null,
36-
custom: null
37-
,
38-
name: 'Location',
39-
description: 'A map with a user\'s GPS location that helps them get to places',
40-
notes: null,
41-
custom: null
13+
vm.features = []
14+
15+
# TODO: replace palceholder features & descriptions
16+
config = {}
17+
18+
config.defaultFeatures = [
19+
id: '123',
20+
name: 'Login',
21+
description: 'Users can login / register for your app',
22+
notes: null,
23+
custom: null,
24+
selected: false
25+
,
26+
id: '124',
27+
name: 'Onboarding',
28+
description: 'Users can see data from social networks (FB, Twitter etc.) in your app',
29+
notes: null,
30+
custom: null,
31+
selected: false
32+
,
33+
id: '125',
34+
name: 'Registration',
35+
description: 'Users can create profiles with personal info',
36+
notes: null,
37+
custom: null,
38+
selected: false
39+
,
40+
id: '126',
41+
name: 'Location',
42+
description: 'A map with a user\'s GPS location that helps them get to places',
43+
notes: null,
44+
custom: null,
45+
selected: false
4246
];
4347

4448
vm.showFeatures = ->
@@ -51,58 +55,59 @@ SubmitWorkFeaturesController = ($scope, SubmitWorkAPIService, API_URL) ->
5155
vm.showDefineFeaturesForm = !vm.showDefineFeaturesForm
5256

5357
vm.hideCustomFeatures= ->
54-
resetCustomFeature()
5558
vm.showDefineFeaturesForm = false
5659

5760
vm.activateFeature = (feature) ->
5861
vm.activeFeature = feature
5962

6063
vm.applyFeature = ->
61-
featureAdded = false
62-
features = vm.work.features
64+
vm.features.forEach (feature) ->
65+
if feature.name == vm.activeFeature.name
66+
feature.selected = true
67+
68+
vm.activeFeature = null
69+
onChange()
6370

64-
features.forEach (feature) ->
65-
featureAdded = true if feature.name == vm.activeFeature.name
71+
vm.removeFeature = ->
72+
vm.features.forEach (feature, index) ->
73+
if feature.name == vm.activeFeature.name
74+
vm.features.splice(index, 1)
6675

67-
unless featureAdded
68-
features.push vm.activeFeature
69-
vm.activeFeature = null
76+
vm.activeFeature = null
77+
onChange()
7078

7179
vm.addCustomFeature = ->
7280
customFeatureValid = vm.customFeature.name && vm.customFeature.description
7381

7482
if customFeatureValid
75-
vm.work.features.push vm.customFeature
76-
resetCustomFeature()
83+
vm.customFeature.selected = true
84+
vm.features.push vm.customFeature
7785
vm.hideCustomFeatures()
86+
onChange()
7887

79-
vm.save = (onSuccess) ->
80-
if vm.workId
81-
params =
82-
id: vm.workId
88+
vm.save = ->
89+
uploaderValid = !vm.featuresUploaderUploading && !vm.featuresUploaderHasErrors
8390

84-
resource = SubmitWorkAPIService.put params, vm.work
85-
resource.$promise.then (response) ->
86-
onSuccess? response
87-
resource.$promise.catch (response) ->
88-
# TODO: add error handling
91+
updates = getUpdates()
8992

90-
vm.submitFeatures = ->
91-
workFeatures = vm.work.features
92-
formsValid = workFeatures.length
93-
uploaderValid = !vm.featuresUploaderUploading && !vm.featuresUploaderHasErrors
93+
hasFeatures = updates.selectedFeatures.length || updates.customFeatures.length
9494

95-
if formsValid && uploaderValid
96-
# TODO: Replace with proper back-end status
97-
vm.work.status = 'FeaturesAdded'
98-
vm.save (response) ->
99-
# TODO: navigate to "proceed to visuals" view
95+
if uploaderValid && hasFeatures
96+
SubmitWorkService.save(updates)
10097

101-
resetCustomFeature = ->
102-
vm.customFeature =
103-
name: null
104-
description: null
105-
custom: true
98+
getUpdates = ->
99+
updates =
100+
selectedFeatures: []
101+
customFeatures: []
102+
vm.features.forEach (feature) ->
103+
if feature.id
104+
if feature.selected
105+
updates.selectedFeatures.push
106+
id: feature.id
107+
else
108+
if feature.selected
109+
updates.customFeatures.push feature
110+
updates
106111

107112
configureUploader = ->
108113
assetType = 'specs'
@@ -117,34 +122,50 @@ SubmitWorkFeaturesController = ($scope, SubmitWorkAPIService, API_URL) ->
117122
workId: vm.workId
118123
assetType: assetType
119124

120-
activate = ->
121-
# initialize custom feature modal inputs
122-
resetCustomFeature()
123-
configureUploader()
125+
onChange = ->
126+
if SubmitWorkService.work.o.hasPending
127+
return false
128+
129+
vm.loading = false
124130

125-
if vm.workId
126-
params =
127-
id : vm.workId
131+
vm.customFeature =
132+
name: null
133+
description: null
134+
custom: true
128135

129-
resource = SubmitWorkAPIService.get params
136+
unless vm.features.length
137+
config.defaultFeatures.forEach (feature) ->
138+
vm.features.push feature
139+
# add any custom features to vm
140+
SubmitWorkService.work.features.forEach (feature) ->
141+
if !feature.id
142+
feature.selected = true
143+
vm.features.push feature
144+
# set already selected features to selected on vm
145+
SubmitWorkService.work.features.forEach (feature) ->
146+
vm.features.forEach (vmFeature) ->
147+
if feature.id == vmFeature.id
148+
vmFeature.selected = true
149+
150+
updates = getUpdates()
151+
vm.selectedFeaturesCount = updates.selectedFeatures.length + updates.customFeatures.length
152+
153+
vm.work = SubmitWorkService.work
130154

131-
resource.$promise.then (response) ->
132-
vm.work = response
133-
# TODO: remove once details are added to payload
134-
vm.work.featuresDetails = null
155+
activate = ->
156+
destroyWorkListener = $rootScope.$on "SubmitWorkService.work:changed", ->
157+
onChange()
135158

136-
resource.$promise.catch (response) ->
137-
# TODO: add error handling
159+
$scope.$on '$destroy', ->
160+
destroyWorkListener()
138161

139-
resource.$promise.finally ->
140-
vm.loading = false
141-
else
142-
vm.loading = false
162+
SubmitWorkService.fetch(vm.workId)
163+
configureUploader()
143164

144165
vm
145166

146167
activate()
147168

148-
SubmitWorkFeaturesController.$inject = ['$scope', 'SubmitWorkAPIService', 'API_URL']
169+
SubmitWorkFeaturesController.$inject = ['$scope', '$rootScope', 'SubmitWorkService', 'SubmitWorkAPIService', 'API_URL']
149170

150171
angular.module('appirio-tech-ng-submit-work').controller 'SubmitWorkFeaturesController', SubmitWorkFeaturesController

src/views/submit-work-features.directive.jade

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ modal.full.define-features(show="vm.showFeaturesModal" background-click-close=tr
3737
ul.features
3838
li
3939
ul
40-
li(ng-repeat="feature in vm.defaultFeatures track by $index")
40+
li(ng-repeat="feature in vm.features track by $index")
4141
button.widest.clean(ng-click="vm.activateFeature(feature)")
42-
.icon(ng-class="{selected: vm.activeFeature.name == feature.name}")
42+
.icon(ng-class="{selected: feature.selected}")
4343

4444
span {{ feature.name }}
4545

@@ -51,12 +51,12 @@ modal.full.define-features(show="vm.showFeaturesModal" background-click-close=tr
5151

5252
ul.contents
5353
li
54-
.default.active(ng-class="{active: !vm.activeFeature}")
54+
.default.active(ng-hide="vm.showDefineFeaturesForm" ng-class="{active: !vm.activeFeature}")
5555
h4 Select and define features for your app
5656

5757
p Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
5858

59-
.description(ng-class="{active: vm.activeFeature}")
59+
.description(ng-hide="vm.showDefineFeaturesForm" ng-class="{active: vm.activeFeature}")
6060
h4 Select and define features for your app
6161

6262
h5 {{ vm.activeFeature.name }} description
@@ -65,7 +65,9 @@ modal.full.define-features(show="vm.showFeaturesModal" background-click-close=tr
6565

6666
textarea.widest(placeholder="Notes..." ng-model="vm.activeFeature.notes")
6767

68-
button.wider.action(ng-click="vm.applyFeature()") apply feature
68+
button.wider.action(ng-if="!vm.activeFeature.selected" ng-click="vm.applyFeature()") apply feature
69+
70+
button.wider.action(ng-if="vm.activeFeature.selected" ng-click="vm.removeFeature()") remove feature
6971

7072
form.new-feature(ng-submit="vm.addCustomFeature()" ng-class="{active: vm.showDefineFeaturesForm}")
7173
h4 Define a new feature
@@ -86,9 +88,9 @@ modal.full.define-features(show="vm.showFeaturesModal" background-click-close=tr
8688
.phone
8789

8890
li
89-
.count {{vm.work.features.length}} features added
91+
.count {{vm.selectedFeaturesCount}} features added
9092

91-
button.wider.action(ng-click="vm.submitFeatures()") next
93+
button.wider.action(ng-click="vm.save()") next
9294

9395
modal.upload-documents(show="vm.showUploadModal" background-click-close=true)
9496
.upload

0 commit comments

Comments
 (0)