diff --git a/apps/mobile-mzima-client/src/app/map/components/filters-form/filters-form.component.ts b/apps/mobile-mzima-client/src/app/map/components/filters-form/filters-form.component.ts index a127984888..b9808da14a 100644 --- a/apps/mobile-mzima-client/src/app/map/components/filters-form/filters-form.component.ts +++ b/apps/mobile-mzima-client/src/app/map/components/filters-form/filters-form.component.ts @@ -8,6 +8,7 @@ import { SavedsearchesService, SurveyItem, SurveysService, + apiHelpers, } from '@mzima-client/sdk'; import { Subject, debounceTime, lastValueFrom, takeUntil } from 'rxjs'; import { AlertService, EnvService, SearchService, SessionService } from '@services'; @@ -311,7 +312,7 @@ export class FiltersFormComponent implements OnChanges, OnDestroy { this.activeFilters = null; } this.surveys = null; - this.surveysService.get().subscribe({ + this.surveysService.getSurveys('', { only: apiHelpers.ONLY.NAME_ID_COLOR }).subscribe({ next: (response) => { this.surveys = response.results; this.initSurveyFilters(isDeplaymentChanged); diff --git a/apps/mobile-mzima-client/src/app/post/post-edit/post-edit.page.html b/apps/mobile-mzima-client/src/app/post/post-edit/post-edit.page.html index 6190505459..cdff98c6f1 100644 --- a/apps/mobile-mzima-client/src/app/post/post-edit/post-edit.page.html +++ b/apps/mobile-mzima-client/src/app/post/post-edit/post-edit.page.html @@ -1,12 +1,15 @@ - + {{'app.loading' | translate}} + + {{'app.loading_post' | translate}} + - Select a survey + {{'app.select_survey' | translate}} + + {{selectedSurvey.name}} + { + if (this.isConnection) { + try { + const response: any = await lastValueFrom( + this.surveysService.getSurveyById(this.selectedSurveyId!), + ); + return response.result; + } catch (err) { + return this.loadSurveyFormLocalDB(); + } + } else { + return this.loadSurveyFormLocalDB(); + } + } + async getSurveys(): Promise { if (this.isConnection) { try { - const response: any = await this.surveysService - .getSurveys('', { + const response: any = await lastValueFrom( + this.surveysService.getSurveys('', { page: 1, order: 'asc', limit: 0, - }) - .toPromise(); + only: apiHelpers.ONLY.NAME_COLOR_PERMISSIONS, + }), + ); const filteredSurveys = response.results.filter((survey: any) => { return ( @@ -227,10 +244,10 @@ export class PostEditPage { return filteredSurveys; } catch (err) { console.log(err); - return this.loadSurveyFormLocalDB(); + return this.loadSurveysFormLocalDB(); } } else { - return this.loadSurveyFormLocalDB(); + return this.loadSurveysFormLocalDB(); } } @@ -275,16 +292,15 @@ export class PostEditPage { : new PostEditForm(this.formBuilder).addFormControl(value, field); } - loadForm(surveyId?: any, updateContent?: PostContent[]) { + async loadForm(surveyId?: any, updateContent?: PostContent[]) { if (surveyId) this.selectedSurveyId = surveyId; if (!this.selectedSurveyId) return; this.clearData(); - - this.selectedSurvey = this.surveyList.find((item: any) => item.id === this.selectedSurveyId); + this.selectedSurvey = await this.getSurvey(); this.requireApproval = this.selectedSurvey?.require_approval; this.color = this.selectedSurvey?.color; this.tasks = this.selectedSurvey?.tasks; - + console.log(this.selectedSurvey); const fields: any = {}; for (const task of this.tasks ?? []) { task.fields @@ -387,8 +403,16 @@ export class PostEditPage { public setCalendar(event: any, key: any, type: string) { this.updateFormControl(key, dateHelper.setDate(event.detail.value, type)); } - - private async loadSurveyFormLocalDB(): Promise { + private async loadSurveyFormLocalDB(): Promise { + if (!this.selectedSurveyId) return null; + try { + const surveysFromDB: any[] = await this.dataBaseService.get(STORAGE_KEYS.SURVEYS); + return surveysFromDB.find((survey) => survey.id === this.selectedSurveyId) || null; + } catch (error: any) { + throw new Error(`Error loading surveys from local database: ${error.message}`); + } + } + private async loadSurveysFormLocalDB(): Promise { try { const surveysFromDB: any[] = await this.dataBaseService.get(STORAGE_KEYS.SURVEYS); const filteredSurveys = surveysFromDB.filter((survey) => { diff --git a/apps/mobile-mzima-client/src/assets/locales/en.json b/apps/mobile-mzima-client/src/assets/locales/en.json index 93959ef938..035a58299b 100644 --- a/apps/mobile-mzima-client/src/assets/locales/en.json +++ b/apps/mobile-mzima-client/src/assets/locales/en.json @@ -75,6 +75,8 @@ "toc_text":"These Terms of Service (the “Terms”) and our Privacy Policy apply to and govern your use of any websites owned or operated by Ushahidi Inc. (“Ushahidi”) that post a link to these Terms (such websites, the “Sites”), the Ushahidi services accessible via the Sites (including any cloud-based servers or platforms) and the Ushahidi mobile device applications (the “Apps”).To make these Terms easier to read, the Sites, our services, platforms, and Apps are collectively called the “Services.” Please note that these Terms do not cover any of our products you download under an open source license. Additionally, these Terms may not apply if you have entered into a separate agreement with Ushahidi that governs your relationship with us, such as a separately-negotiated enterprise agreement.Agreement To Termsthese Terms, do not use the Services. If you are accessing and using the Services on behalf of a company (such as your employer) or other legal entity, you represent and warrant that you have the authority to bind that company or other legal entity to these Terms.In that case, “you” and “your” will refer to that company or other legal entity.", "skip": "Skip", "loading":"Fetching Surveys...", + "loading_post":"Loading post", + "select_survey": "Select a survey", "emtpy_field_error": "This field cannot be empty", "info" : { "auth_not_online" : "Sorry. You're offline…please check your internet connection",
{{'app.loading' | translate}}
{{'app.loading_post' | translate}}
These Terms of Service (the “Terms”) and our Privacy Policy apply to and govern your use of any websites owned or operated by Ushahidi Inc. (“Ushahidi”) that post a link to these Terms (such websites, the “Sites”), the Ushahidi services accessible via the Sites (including any cloud-based servers or platforms) and the Ushahidi mobile device applications (the “Apps”).
To make these Terms easier to read, the Sites, our services, platforms, and Apps are collectively called the “Services.” Please note that these Terms do not cover any of our products you download under an open source license. Additionally, these Terms may not apply if you have entered into a separate agreement with Ushahidi that governs your relationship with us, such as a separately-negotiated enterprise agreement.
these Terms, do not use the Services. If you are accessing and using the Services on behalf of a company (such as your employer) or other legal entity, you represent and warrant that you have the authority to bind that company or other legal entity to these Terms.
In that case, “you” and “your” will refer to that company or other legal entity.