Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE #ED-540 feat : Pii consent flow changes done for Survey #395

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 53 additions & 7 deletions src/app/manage-learn/questionnaire/questionnaire.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { Network } from '@awesome-cordova-plugins/network/ngx';
import { AppHeaderService } from '../../../services/app-header.service';
import { CommonUtilService } from '../../../services/common-util.service';
import { GenericPopUpService } from '../shared';
import { SurveyProviderService } from '../core/services/survey-provider.service';
import { UpdateLocalSchoolDataService } from '../core/services/update-local-school-data.service';

@Component({
selector: 'app-questionnaire',
Expand Down Expand Up @@ -52,6 +54,7 @@ export class QuestionnairePage implements OnInit, OnDestroy {
isSurvey : boolean = false;
payload: {}
isNewProgram: boolean = false
surveyId
constructor(
// public navCtrl: NavController,
// public navParams: NavParams,
Expand All @@ -74,7 +77,9 @@ export class QuestionnairePage implements OnInit, OnDestroy {
private translate: TranslateService,
private router: Router,
private commonUtilService:CommonUtilService,
private popupService: GenericPopUpService
private popupService: GenericPopUpService,
private surveyProvider: SurveyProviderService,
private ulsdp: UpdateLocalSchoolDataService
) {
this.routerParam.queryParams.subscribe((params) => {
this.submissionId = params.submisssionId;
Expand All @@ -83,13 +88,15 @@ export class QuestionnairePage implements OnInit, OnDestroy {
this.schoolName = params.schoolName;
this.isSurvey = params.isSurvey == 'true';
this.schoolData.programJoined = params?.programJoined == 'true'
this.surveyId = params.surveyId
});
// State is using for Template view for Deeplink.
this.extrasState = this.router.getCurrentNavigation().extras.state;
if(this.extrasState){
this.isTargeted = this.extrasState.isATargetedSolution;
this.isSurvey = this.extrasState?.isSurvey || false
}
if(this.extrasState && !this.isTargeted){
if(this.extrasState && !this.isTargeted && !this.isSurvey){
this.showMessageForNONTargetUsers();
}
this._appHeaderSubscription = this.headerService.headerEventEmitted$.subscribe((eventName) => {
Expand Down Expand Up @@ -151,10 +158,13 @@ export class QuestionnairePage implements OnInit, OnDestroy {
if(!data.programJoined && this.isNewProgram && this.isSurvey){
this.joinProgram()
}
if(this.isNewProgram && data.programJoined && data?.requestForPIIConsent){
if(this.isNewProgram && data.programJoined && data?.requestForPIIConsent && !data?.consentShared){
let profileData = await this.utils.getProfileInfo();
await this.popupService.getConsent('Program',this.payload,this.schoolData,profileData,'FRMELEMNTS_MSG_PROGRAM_JOINED_SUCCESS').then((response)=>{
if(response){
if(this.isSurvey){
this.getSurveyDetails()
}
}
})
}
Expand Down Expand Up @@ -574,9 +584,10 @@ export class QuestionnairePage implements OnInit, OnDestroy {
this.showConsentPopup()
if(!this.schoolData.requestForPIIConsent){
this.commonUtilService.showToast('FRMELEMNTS_MSG_PROGRAM_JOINED_SUCCESS','','',9000,'top');
if(this.isSurvey){
document.getElementById('stop').style.pointerEvents = 'auto';
}
}
if(this.isSurvey){
document.getElementById('stop').style.pointerEvents = 'auto';

}
}
})
Expand All @@ -589,6 +600,7 @@ export class QuestionnairePage implements OnInit, OnDestroy {
if(data){
if(this.isSurvey){
document.getElementById('stop').style.pointerEvents = 'auto';
this.getSurveyDetails()
}
}
})
Expand All @@ -602,5 +614,39 @@ export class QuestionnairePage implements OnInit, OnDestroy {
this.allowStart()
}
}


async getSurveyDetails(){
this.surveyProvider
.getDetailsById(this.surveyId, this.schoolData.solution._id)
.then(async(res) => {
if (res.result == false) {
this.surveyProvider.showMsg('surveyExpired');
this.location.back()
return;
}
this.ulsdp.mapSubmissionDataToQuestion(res.result,false,true);
await this.surveyProvider
.storeSurvey(res.result.assessment.submissionId, res.result)
.then((survey) => {
this.extrasState = null
this.submissionId = survey.assessment.submissionId
this.redirect(survey.assessment.submissionId)
});
});
}


redirect(submissionId){
this.router.navigate([RouterLinks.QUESTIONNAIRE], {
replaceUrl: true,
queryParams: {
submisssionId: submissionId,
evidenceIndex: 0,
sectionIndex: 0,
isSurvey:true,
},
});
this.ngOnInit()
}

}
2 changes: 1 addition & 1 deletion src/app/manage-learn/shared/generic.popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async closeConsent(){
data=response.consents[0]
}).catch(async (error)=>{
if (!error.response.body.result.consent && error.response.responseCode === 404) {
await this.showConsent(type, payload, details, profileData,message);
data = await this.showConsent(type, payload, details, profileData,message);
} else if (error.code === 'NETWORK_ERROR') {
this.commonUtils.showToast('ERROR_NO_INTERNET_MESSAGE');
}
Expand Down
82 changes: 77 additions & 5 deletions src/app/manage-learn/survey/survey-home/survey-home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SurveyProviderService } from '../../core/services/survey-provider.servi
import { KendraApiService } from '../../core/services/kendra-api.service';
import { Router } from '@angular/router';
import { UpdateLocalSchoolDataService } from '../../core/services/update-local-school-data.service';
import { AssessmentApiService } from '../../core/services/assessment-api.service';
@Component({
selector: 'app-survey-home',
templateUrl: './survey-home.component.html',
Expand All @@ -28,6 +29,7 @@ export class SurveyHomeComponent {
submissionArr: any;
count: any;
isReport: boolean = false;
surveyId
constructor(
private headerService: AppHeaderService,
private router: Router,
Expand All @@ -38,6 +40,7 @@ export class SurveyHomeComponent {
private kendra: KendraApiService,
private toast: ToastService,
private ulsdp: UpdateLocalSchoolDataService,
private assessmentService: AssessmentApiService
) {
const extrasState = this.router.getCurrentNavigation().extras.state;
if (extrasState) {
Expand All @@ -52,7 +55,7 @@ export class SurveyHomeComponent {
ionViewWillEnter() {
this.page=1
this.surveyList = [];
this.link ? this.deepLinkRedirect() : this.getSurveyListing();
this.link ? this.verifyLink(this.link) : this.getSurveyListing();

this.headerConfig = this.headerService.getDefaultPageConfig();
this.headerConfig.actionButtons = [];
Expand Down Expand Up @@ -107,7 +110,6 @@ export class SurveyHomeComponent {

applySubmission(): void {
this.surveyList.map((survey) => {
console.log(this.submissionArr.includes(survey.submissionsId));
this.submissionArr.includes(survey.submissionId) ? (survey.downloaded = true) : null;
});
}
Expand All @@ -134,7 +136,8 @@ export class SurveyHomeComponent {
});
}

onSurveyClick(survey) {
async onSurveyClick(survey) {
this.surveyId = survey._id
if (!this.isReport) {

if (survey.status == 'expired') {
Expand All @@ -144,6 +147,11 @@ export class SurveyHomeComponent {
}

// surveyId changed to _id
if(!survey.submissionId){
this.getSurveyTemplateDetails(survey)
return
}

survey.downloaded
? this.redirect(survey.submissionId)
: this.getSurveyById(survey._id, survey.solutionId, survey.isCreator);
Expand All @@ -153,15 +161,17 @@ export class SurveyHomeComponent {

}

redirect(submissionId: any): void {
redirect(submissionId: any,data?): void {
this.router.navigate([RouterLinks.QUESTIONNAIRE], {
replaceUrl: this.link ? true : false,
queryParams: {
submisssionId: submissionId,
evidenceIndex: 0,
sectionIndex: 0,
isSurvey:true
isSurvey:true,
surveyId:this.surveyId
},
state:data?{...data,isSurvey:true}:null
});
}

Expand Down Expand Up @@ -231,4 +241,66 @@ export class SurveyHomeComponent {
this.page = this.page + 1;
this.getSurveyListing();
}

async getSurveyTemplateDetails(data) {
let payload = await this.utils.getProfileData();
const config = {
url: urlConstants.API_URLS.TEMPLATE_DETAILS + data.solutionId,
payload: payload,
};
this.assessmentService.post(config).subscribe((success) => {
if (success.result) {
if(success.result.hasOwnProperty('requestForPIIConsent') && !success.result.programJoined){
this.redirect(success.result.assessment.submissionId,success.result);
}else{
data.downloaded
? this.redirect(data.submissionId)
: this.getSurveyById(data._id, data.solutionId, data.isCreator);
}
}else{
this.toast.showMessage('FRMELEMNTS_MSG_TEMPLATE_DETAILS_NOTFOUND','danger');
}
},error =>{
this.toast.showMessage('FRMELEMNTS_MSG_TEMPLATE_DETAILS_NOTFOUND','danger');
});
}

async verifyLink(link) {
this.loader.startLoader();
let payload = await this.utils.getProfileData('SERVER');
const config = {
url: urlConstants.API_URLS.DEEPLINK.VERIFY_LINK + link+'?createProject=false',
payload: payload,
};
let resp = await this.kendra.post(config).toPromise();
if (resp && resp.result) {
this.loader.stopLoader();
switch (resp.result.type) {
case 'survey':
let details = resp.result
await this.localStorage
.getLocalStorage(storageKeys.submissionIdArray)
.then(async (allId) => {
await allId.includes(details.submissionId) ? (details.downloaded = true) : null;
});
resp.result.submissionId ? this.checkIsDownloaded(details) : this.getSurveyTemplateDetails(details);
default:
break;
}
}else{
this.loader.stopLoader();
if(resp && resp.status){
this.toast.showMessage('FRMELEMNTS_MSG_INVALID_LINK','danger');
}
}
}

async checkIsDownloaded(details){
if(details.downloaded){
this.redirect(details.submissionId)
}else{
this.getSurveyById(details.surveyId, details.solutionId, details.isCreator)
}
}

}