Skip to content

Commit

Permalink
New survey interface
Browse files Browse the repository at this point in the history
  • Loading branch information
akariv committed Nov 24, 2024
1 parent 58a70e0 commit cff9e03
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 211 deletions.
4 changes: 2 additions & 2 deletions ui/src/app/editable-table/editable-table.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
*ngIf='kind(field) === "supplier-selection"'
></app-tender-suppliers-editor>
<app-tender-survey-control
[survey]='row.survey || null'
[survey]='row.tqs || null'
[record]='row'
[context]='record.datarecord'
(changed)='emit(row, field); saveChanges()'
(modal)='modal.emit($event)'
*ngIf='kind(field) === "survey"'
*ngIf='kind(field) === "survey" && row.tqs?.required'
></app-tender-survey-control>
</td>
<td *ngIf='config.rowDelete && rows.length - 1 === rowidx'><span class='delete' (click)='delete(row)'><i class="fas fa-trash-alt"></i></span></td>
Expand Down
1 change: 0 additions & 1 deletion ui/src/app/editable-table/editable-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class EditableTableComponent implements OnInit {
}

saveChanges() {
console.log('TTTTS0');
this.save.emit();
}
}
117 changes: 75 additions & 42 deletions ui/src/app/obudget-api.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { EMPTY, from, Subject } from 'rxjs';
import { catchError, concatMap, debounceTime, map } from 'rxjs/operators';
import { catchError, concatMap, debounceTime, map, take, tap } from 'rxjs/operators';
import * as Sentry from "@sentry/angular-ivy";
import { AuthService } from 'dgp-oauth2-ng';
import { ApiService } from 'etl-server';
Expand All @@ -18,6 +18,8 @@ export class ObudgetApiService {
private email: any;
public errorMsg: string = null;
private syncTendersQueue = new Subject<any>();
private syncedTendersQueue = new Subject<any[]>();
public submittedTenders: any = {};

constructor(private http: HttpClient, private auth: AuthService, private etlApiService: ApiService) {
this.errors.subscribe((msg) => {
Expand All @@ -32,7 +34,21 @@ export class ObudgetApiService {
this.email = user.profile.email;
}
});
this.syncTendersQueue.pipe(concatMap((rec) => this.syncTendersInternal(rec))).subscribe();
this.syncTendersQueue.pipe(
tap((tenders) => {
this.updateTenderSubmittedStatus(tenders);
}),
concatMap((tenders) =>
this.getSubmittedTenders().pipe(
map(() => tenders)
)
),
tap((tenders) => {
this.updateTenderSubmittedStatus(tenders);
})
).subscribe((tenders) => {
this.syncedTendersQueue.next(tenders);
});
}

handleErrorMsg() {
Expand Down Expand Up @@ -114,67 +130,84 @@ export class ObudgetApiService {
);
}

syncTendersInternal({body, tenders}) {
return this.http.post(`${environment.api_endpoint}/sync-tenders`, body, this.etlApiService.httpOptions).pipe(
catchError((err) => {
return EMPTY;
}),
map((result: any) => {
result.tenders.forEach((t) => {
const key = t.key;
const tender = tenders.find((x) => x.tender_key === key);
if (tender) {
tender.survey = tender.survey || {};
tender.survey.recId = t.recId;
tender.survey.flagName = t.flag;
tender.survey.submitted = !!t.submitted;
}
});
}),
getSubmittedTenders() {
return this.http.get(`${environment.api_endpoint}/sync-tenders`, this.etlApiService.httpOptions).pipe(
tap((result: any) => {
this.submittedTenders = Object.assign({}, (result.submitted_flag_ids || {}), (result.submitted_base_ids || {}));
})
);
}

updateTenderSubmittedStatus(tenders) {
for (const tender of tenders) {
if (!!this.submittedTenders[tender.tender_key]) {
tender.tqs = tender.tqs || {};
tender.tqs.submitted = true;
tender.tqs.recId = this.submittedTenders[tender.tender_key];
} else {
tender.tqs = tender.tqs || {};
tender.tqs.submitted = false;
}
}
}

syncTenders(record: any) {
const office = record.office;
const unit = record.unit;
const service_name = record.name;
const service_id = record.id;
const tenders = record.tenders.filter((t) => {
t.survey = null;
t.tqs = t.tqs || {};
t.tqs.required = false;;
const start_year = parseInt((t.publication_date || '0-').split('-')[0]);
if (start_year < 2024) {
return false;
}
if (t.tender_type !== 'exemptions') {
t.survey = t.survey || {};
return !!t.survey.flag;
t.tqs = t.tqs || {};
return true;
} else if (
t.tender_type === 'exemptions' && (
t.entity_kind === 'municipality' ||
(t.regulation || '').indexOf('מיזם משותף') >= 0 ||
(t.regulation || '').indexOf('ספק יחיד') >= 0
)
) {
t.survey = t.survey || {};
t.survey.flag = 'no';
t.tqs = t.tqs || {};
t.tqs.flag = 'no';
return true;
}
return false;
}).map((t) => {
const start_date = (t.date_range || '-').split('-')[0];
const end_date = (t.date_range || '-').split('-')[1] || t.end_date;

return {
tender_key: t.tender_key,
tender_id: t.tender_id === 'none' ? null : t.tender_id,
publication_number: t.tender_key.split(':')[0],
publication_name: t.description,
flag: t.survey.flag === 'yes',
active: t.active === 'yes',
start_date: start_date || null,
end_date: end_date || null,
}
t.tqs.required = true;
return t;
});
if (tenders.length === 0) {
return;
}
const body = {service_id, service_name, office, unit, tenders};
this.syncTendersQueue.next({body, tenders: record.tenders});
this.syncedTendersQueue.pipe(
take(1),
).subscribe((tenders) => {
const office = record.office;
const unit = record.unit;

for (const t of tenders) {
const tender_key = t.tender_key;
const tender_name = t.description;
if (t.tqs.flag === 'yes') {
if (!t.tqs.submitted) {
t.tqs.link = 'https://form.jotform.com/242954939134062?' +
'office_name=' + encodeURIComponent(office) + '&' +
'devision_name=' + encodeURIComponent(unit) + '&' +
'unit_name=' + encodeURIComponent(unit) + '&' +
'tender_ID=' + encodeURIComponent(tender_key) + '&' +
'tender_name=' + encodeURIComponent(tender_name);
} else {
t.tqs.link = 'https://airtable.com/appkFwqZCU6MFquJh/pag7DVwsy7HFIWno5?2cOrN=' + t.tqs.recId;
}
} else {
t.tqs.link = null;
}
}
});
this.syncTendersQueue.next(tenders);
}

cleanHighlights(item) {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/social-service-editor/datatypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ export const tendersTenderConfig = {
fullRow: 7
},
{
name: 'survey',
name: 'tqs',
display: 'מדידה',
kind: 'survey',
fullRow: 8
Expand Down Expand Up @@ -660,7 +660,7 @@ export const tendersExemptionConfig = {
}
},
{
name: 'survey',
name: 'tqs',
display: 'מדידה',
kind: 'survey',
fullRow: 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,6 @@ <h3>מכרזים אפשריים</h3>
<app-budget-searcher *ngIf='showSearch === "budget"' (choose)='ssu.addBudgetItem($event)'></app-budget-searcher>
<app-tender-searcher *ngIf='showSearch === "tender"' [office]='datarecord && datarecord.office' [existing]='datarecord.tenders' (choose)='ssu.connectTender({row: $event})'></app-tender-searcher>
<app-supplier-searcher *ngIf='showSearch === "supplier"' (choose)='ssu.connectSupplier({row: $event, field: "related"})'></app-supplier-searcher>
<app-survey *ngIf='surveyRecId?.length && surveyFlag?.length' [recId]='surveyRecId' [flag]='surveyFlag'></app-survey>
<app-survey *ngIf='surveyLink?.length' [link]='surveyLink'></app-survey>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export class SocialServiceEditorComponent implements OnInit {

modalActive = false;
showSearch: string = '';
surveyFlag: string = '';
surveyRecId: string = '';
surveyLink: string = '';
valid = true;
errorMsg: string = '';
errorMsgMajor = false;
Expand Down Expand Up @@ -218,22 +217,22 @@ export class SocialServiceEditorComponent implements OnInit {
return false;
}

modal(kind) {
modal(kind: string) {
if (kind) {
if (kind.indexOf('survey:') === 0) {
this.modalActive = true;
const [_, surveyFlag, surveyRecId] = kind.split(':');
this.surveyRecId = surveyRecId;
this.surveyFlag = surveyFlag;
this.surveyLink = kind.slice(7);
} else {
this.modalActive = true;
this.showSearch = kind;
}
} else {
if (this.surveyLink) {
this.ssu.refresh();
}
this.modalActive = false;
this.showSearch = '';
this.surveyRecId = '';
this.surveyFlag = '';
this.surveyLink = '';
}
}

Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/social-service-editor/social-service-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export class SocialServiceUtils {
decision,
description,
start_date || '&nbsp;-<br/>' || end_date as date_range,
publication_date,
regulation,
page_url,
coalesce(supplier, entity_name) as supplier,
Expand Down Expand Up @@ -311,6 +312,7 @@ export class SocialServiceUtils {
decision,
description,
start_date || '&nbsp;-<br/>' || end_date as date_range,
publication_date,
regulation,
page_url,
coalesce(supplier, entity_name) as supplier,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ng-container *ngIf='!editing'>
<span>מפעילים: {{(value && value.length > 0) ? commaSeparatedList : 'לא סומנו המפעילים הזוכים'}}</span>
<span class='pencil' (click)='editing = !editing'><i class="fas fa-edit"></i></span>
<span>מפעילים: {{(value && value.length > 0) ? commaSeparatedList : 'לא סומנו המפעילים הזוכים'}}</span>
</ng-container>
<ng-container *ngIf='editing'>
<ng-container *ngIf='context.datarecord.suppliers && context.datarecord.suppliers.length > 0'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@
}

padding: 4px;
gap: 8px;
gap: 12px;

.pencil {
cursor: pointer;
margin: 0;
}

i {
flex: 1 0 18px;
text-align: center;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
<div class='container' *ngIf='survey !== null'>
<div *ngIf='survey.submitted'>שאלון מדידת ״רכש חברתי מיטבי״ הוגש</div>
<ng-container *ngIf='!survey.submitted && survey.recId'>
<a *ngIf='survey.flag === "no"' (click)='openSurvey("base", survey.recId)'>קישור לשאלון מדידה להליך בסיס</a>
<a *ngIf='survey.flag === "yes"' (click)='openSurvey("flag", survey.recId)'>קישור לשאלון מדידה להליך דגל</a>
<ng-container *ngIf='survey.submitted'>
<i class="fas fa-chart-bar"></i>
<div>
<span>שאלון מדידת ״רכש חברתי מיטבי״ הוגש</span><br/>
<a [href]='survey.link' target='_blank'>צפיה במדדים עבור מכרז זה</a>
</div>
</ng-container>
<ng-container *ngIf='!survey.submitted && !survey.recId && record.tender_type !== "exemptions" && !survey.flag'>
<ng-container *ngIf='!survey.submitted && survey.link'>
<i class="fas fa-edit"></i>
<a *ngIf='survey.flag === "no"' (click)='openSurvey()'>קישור לשאלון מדידה להליך בסיס</a>
<a *ngIf='survey.flag === "yes"' (click)='openSurvey()'>קישור לשאלון מדידה להליך דגל</a>
</ng-container>
<ng-container *ngIf='!survey.submitted && record.tender_type !== "exemptions" && !survey.flag'>
<i class="fas fa-exclamation-circle"></i>
<strong>בחירת סוג מכרז עבור מדידת ״רכש חברתי מיטבי״:</strong>
<select [(ngModel)]='flag'>
<option [ngValue]='null'>בחירה</option>
<option [ngValue]='"yes"'>מכרז דגל</option>
<option [ngValue]='"no"'>מכרז בסיס</option>
</select>
</ng-container>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
display: flex;
flex-flow: row;
align-items: center;
padding: 4px;
gap: 12px;
white-space: nowrap;

i {
flex: 1 0 18px;
text-align: center;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ export class TenderSurveyControlComponent {
return this.survey.flag || null;
}

openSurvey(flag: string, recId: string) {
this.modal.emit(`survey:${flag}:${recId}`);
openSurvey() {
this.modal.emit('survey:' + this.survey.link);
}

clear() {
if (!this.survey) {
return;
}
for (const key of Object.keys(this.survey)) {
this.survey[key] = null;
}
this.changed.emit();
this.api.syncTenders(this.context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class SocialServiceListUpdaterComponent implements OnInit {
constructor(public api: ObudgetApiService, private etlApi: ApiService, private cachedApi: CachedApiService,) { }

ngOnInit(): void {
console.log('datarecords = ', this.datarecords);
// console.log('datarecords = ', this.datarecords);
}

start() {
Expand Down
10 changes: 4 additions & 6 deletions ui/src/app/survey/survey.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<div class='menu'>
<div class='menu-item' *ngFor='let item of (menuItems[flag] || [])' [class.active]='item.active' (click)='select(item)'>
<img [src]='"assets/survey/" + item.icon + ".png"' />
<span class='label'>{{item.label}}</span>
</div>
</div>
<iframe [src]='safeLink' *ngIf='safeLink' width='100%' height='100%'
frameborder='0' marginheight='0' marginwidth='0' style='border: none'
sandbox='allow-scripts allow-forms'
></iframe>
Loading

0 comments on commit cff9e03

Please sign in to comment.