Revision 57772
Added by Konstantinos Triantafyllou over 4 years ago
home.component.ts | ||
---|---|---|
7 | 7 |
import {Option, StakeholderUtils} from "../utils/indicator-utils"; |
8 | 8 |
import {FormBuilder, FormGroup, Validators} from "@angular/forms"; |
9 | 9 |
import {AlertModal} from "../openaireLibrary/utils/modal/alert"; |
10 |
import {StakeholderCreator} from "../utils/entities/stakeholderCreator"; |
|
10 | 11 |
|
11 | 12 |
@Component({ |
12 | 13 |
selector: 'home', |
... | ... | |
145 | 146 |
} |
146 | 147 |
|
147 | 148 |
public editStakeholder(stakeholder: Stakeholder = null, isDefault: boolean = false) { |
148 |
if(isDefault) { |
|
149 |
this.index = (stakeholder)?this.defaultStakeholders.findIndex(value => value._id === stakeholder._id):-1;
|
|
149 |
if (isDefault) {
|
|
150 |
this.index = (stakeholder) ? this.defaultStakeholders.findIndex(value => value._id === stakeholder._id) : -1;
|
|
150 | 151 |
} else { |
151 |
this.index = (stakeholder)?this.stakeholders.findIndex(value => value._id === stakeholder._id):-1;
|
|
152 |
this.index = (stakeholder) ? this.stakeholders.findIndex(value => value._id === stakeholder._id) : -1;
|
|
152 | 153 |
} |
153 |
if(!stakeholder) { |
|
154 |
if (!stakeholder) {
|
|
154 | 155 |
this.stakeholder = new Stakeholder(null, null, null, |
155 |
null, null, isDefault, null, false, false); |
|
156 |
null, null, isDefault, null, false, false, null);
|
|
156 | 157 |
} else { |
157 | 158 |
this.stakeholder = stakeholder; |
158 | 159 |
} |
159 |
this.stakeholderFb = this.fb.group( {
|
|
160 |
_id: this.fb.control(stakeholder._id),
|
|
161 |
index_name: this.fb.control(stakeholder.index_name, Validators.required),
|
|
162 |
index_id: this.fb.control(stakeholder.index_id, Validators.required),
|
|
163 |
index_shortName: this.fb.control(stakeholder.index_shortName, Validators.required),
|
|
164 |
isDefaultProfile: this.fb.control(stakeholder.isDefaultProfile),
|
|
165 |
alias: this.fb.control(stakeholder.alias, Validators.required),
|
|
166 |
isPublic: this.fb.control(stakeholder.isPublic),
|
|
167 |
isActive: this.fb.control(stakeholder.isActive),
|
|
168 |
type: this.fb.control(stakeholder.type, Validators.required),
|
|
169 |
topics: this.fb.control(stakeholder.topics)
|
|
160 |
this.stakeholderFb = this.fb.group({ |
|
161 |
_id: this.fb.control(this.stakeholder ._id),
|
|
162 |
index_name: this.fb.control(this.stakeholder .index_name, Validators.required),
|
|
163 |
index_id: this.fb.control(this.stakeholder .index_id, Validators.required),
|
|
164 |
index_shortName: this.fb.control(this.stakeholder .index_shortName, Validators.required),
|
|
165 |
isDefaultProfile: this.fb.control(this.stakeholder .isDefaultProfile),
|
|
166 |
alias: this.fb.control(this.stakeholder .alias, Validators.required),
|
|
167 |
isPublic: this.fb.control(this.stakeholder .isPublic),
|
|
168 |
isActive: this.fb.control(this.stakeholder .isActive),
|
|
169 |
type: this.fb.control(this.stakeholder .type, Validators.required),
|
|
170 |
topics: this.fb.control(this.stakeholder .topics)
|
|
170 | 171 |
}); |
171 |
if(this.index !== -1 && this.stakeholderFb.value.type) { |
|
172 |
if (this.index !== -1 && this.stakeholderFb.value.type) {
|
|
172 | 173 |
this.stakeholderFb.get('type').disable(); |
173 | 174 |
} |
174 | 175 |
this.editStakeholderModal.cancelButtonText = 'Cancel'; |
... | ... | |
179 | 180 |
} |
180 | 181 |
|
181 | 182 |
public saveStakeholder() { |
182 |
if(this.index === -1) { |
|
183 |
this.stakeholderService.getDefaultStakeholders(this.properties.monitorServiceAPIURL, |
|
184 |
this.stakeholderFb.value.type).subscribe( stakeholders => { |
|
185 |
this.stakeholderFb.setControl('topic', this.fb.control(stakeholders[0].topics)); |
|
186 |
this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.value).subscribe(stakeholder => { |
|
187 |
if(stakeholder.isDefaultProfile) { |
|
188 |
this.defaultStakeholders.push(stakeholder); |
|
189 |
} else { |
|
190 |
this.stakeholders.push(stakeholder); |
|
191 |
} |
|
192 |
}); |
|
183 |
if (this.index === -1) { |
|
184 |
// this.stakeholderFb.setValue(this.stakeholderUtils. |
|
185 |
// createFunderFromDefaultProfile(this.stakeholderFb.value, |
|
186 |
// this.defaultStakeholders.find( value => value.type === this.stakeholderFb.value.type).topics)); |
|
187 |
this.stakeholderFb.setValue(this.stakeholderUtils. |
|
188 |
createFunderFromDefaultProfile(this.stakeholderFb.value, StakeholderCreator.createFunderDefaultProfile().topics)); |
|
189 |
this.stakeholderService.buildStakeholder(this.properties.monitorServiceAPIURL, this.stakeholderFb.value).subscribe(stakeholder => { |
|
190 |
if (stakeholder.isDefaultProfile) { |
|
191 |
this.defaultStakeholders.push(stakeholder); |
|
192 |
} else { |
|
193 |
this.stakeholders.push(stakeholder); |
|
194 |
} |
|
193 | 195 |
}); |
194 | 196 |
} else { |
195 | 197 |
this.stakeholderFb.get('type').enable(); |
196 | 198 |
this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.value).subscribe(stakeholder => { |
197 |
if(stakeholder.isDefaultProfile) { |
|
199 |
if (stakeholder.isDefaultProfile) {
|
|
198 | 200 |
this.defaultStakeholders[this.index] = stakeholder; |
199 | 201 |
} else { |
200 | 202 |
this.stakeholders[this.index] = stakeholder; |
... | ... | |
204 | 206 |
} |
205 | 207 |
|
206 | 208 |
public deleteStakeholderOpen(stakeholder: Stakeholder, isDefault = false) { |
207 |
if(isDefault) { |
|
208 |
this.index = (stakeholder)?this.defaultStakeholders.findIndex(value => value._id === stakeholder._id):-1;
|
|
209 |
if (isDefault) {
|
|
210 |
this.index = (stakeholder) ? this.defaultStakeholders.findIndex(value => value._id === stakeholder._id) : -1;
|
|
209 | 211 |
} else { |
210 |
this.index = (stakeholder)?this.stakeholders.findIndex(value => value._id === stakeholder._id):-1;
|
|
212 |
this.index = (stakeholder) ? this.stakeholders.findIndex(value => value._id === stakeholder._id) : -1;
|
|
211 | 213 |
} |
212 | 214 |
} |
213 | 215 |
|
Also available in: Unified diff
[MonitorDashboard]: Save stakeholder