Skip to content

Commit

Permalink
Merge branch 'online-surey-with-event-form-and-throttled-save' into r…
Browse files Browse the repository at this point in the history
…elease/v3.32.0
  • Loading branch information
esurface committed Jun 25, 2024
2 parents b1f13e1 + 21f922e commit cc68399
Show file tree
Hide file tree
Showing 110 changed files with 5,357 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class SyncingService {
doc['items'][0]['inputs'].push({ name: 'tabletUserName', value: username });
// Redact any fields marked as private.
doc['items'].forEach(item => {
item['inputs'].forEach(input => {
item['inputs'].forEach(input => {
if (input.private) {
input.value = '';
}
Expand Down
9 changes: 5 additions & 4 deletions develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ fi

if echo "$T_MODULES" | grep mysql; then
./mysql-create-dirs.sh
fi

if echo "$T_USE_MYSQL_CONTAINER" | grep "true"; then
if echo "$T_USE_MYSQL_CONTAINER" | grep "true"; then
./mysql-start-container.sh
echo "Waiting 60 seconds for mysql container to start..."
sleep 60
./mysql-setup.sh
sleep 60
./mysql-setup.sh
fi
fi

if echo "$T_MYSQL_PHPMYADMIN" | grep "TRUE"; then
Expand Down Expand Up @@ -230,6 +230,7 @@ OPTIONS="--link $T_COUCHDB_CONTAINER_NAME:couchdb \
--volume $(pwd)/editor/src:/tangerine/editor/src:delegated \
--volume $(pwd)/translations:/tangerine/translations:delegated \
--volume $(pwd)/online-survey-app/src:/tangerine/online-survey-app/src:delegated \
--volume $(pwd)/online-survey-app/dist:/tangerine/online-survey-app/dist:delegated \
--volume $(pwd)/tangy-form-editor:/tangerine/tangy-form-editor:delegated \
--volume $(pwd)/tangy-form:/tangerine/tangy-form:delegated \
tangerine/tangerine:local
Expand Down
2 changes: 1 addition & 1 deletion docs/editor/content-sets.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Be sure to update any cron jobs to include the new build commands if they are us

``
git pull
npm rn install-server
npm run install-server
npm build
``

Expand Down
5 changes: 4 additions & 1 deletion editor/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ export class AppComponent implements OnInit, OnDestroy {
this.isConfirmDialogActive = false;
} else {
await this.logout();
}
}
} else if (Date.now() > expiryTimeInMs && this.isConfirmDialogActive) {
// the token expired, and we warned them. Time to log out.
await this.logout();
}
}

Expand Down
1 change: 1 addition & 0 deletions editor/src/app/case/classes/event-form-definition.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class EventFormDefinition {
allowDeleteIfFormNotStarted:string
onEventFormOpen?:string
onEventFormClose?:string
allowOnline?:boolean

constructor() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
<div [innerHTML]="renderedTemplateListItemPrimary|unsanitizeHtml"></div>
<div [innerHTML]="renderedTemplateListItemSecondary|unsanitizeHtml" secondary></div>
</div>
<span *ngIf="!eventFormArchived && !eventForm.formResponseId && canLinkToOnlineSurvey">
<button class="tangy-small-list-icon" [matMenuTriggerFor]="linkMenu" (click)="showLinkMenu(); $event.stopPropagation()">
<mwc-icon>share</mwc-icon>
</button>
<mat-menu #linkMenu="matMenu">
<button mat-menu-item tangy-small-list-icon (click)="onCopyLinkClick()">
<mwc-icon>link</mwc-icon>
</button>
<button mat-menu-item tangy-small-list-icon (click)="onQRCodeLinkClick()">
<mwc-icon>qr_code</mwc-icon>
</button>
<button mat-menu-item tangy-small-list-icon (click)="$event.stopPropagation()">
<a href="{{surveyLinkUrl}}" target="_new"><mwc-icon>open_in_new</mwc-icon></a>
</button>
</mat-menu>
</span>
<span *ngIf="canUserDeleteForms">
<button (click)="onDeleteFormClick(); $event.stopPropagation()" class="tangy-small-list-icon">
<mwc-icon>delete</mwc-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import { TangyFormService } from 'src/app/tangy-forms/tangy-form.service';
import { CaseService } from '../../services/case.service';
import { AppConfigService } from 'src/app/shared/_services/app-config.service';
import { t } from 'tangy-form/util/t.js'


import { GroupsService } from 'src/app/groups/services/groups.service';
import { TangyErrorHandler } from 'src/app/shared/_services/tangy-error-handler.service';
import * as qrcode from 'qrcode-generator-es6';

@Component({
selector: 'app-event-form-list-item',
Expand Down Expand Up @@ -47,20 +48,37 @@ export class EventFormListItemComponent implements OnInit {
canUserDeleteForms: boolean;
groupId:string;
eventFormArchived: boolean = false;
canLinkToOnlineSurvey: boolean = false;
response:any
surveyLinkUrl:string;

constructor(
private formService: TangyFormService,
private ref: ChangeDetectorRef,
private router:Router,
private caseService: CaseService
private caseService: CaseService,
private groupsService: GroupsService,
private tangyErrorHandler: TangyErrorHandler
) {
ref.detach();
}

async ngOnInit() {
this.groupId = window.location.pathname.split('/')[2]

const group = await this.groupsService.getGroupInfo(this.groupId);
const groupOnlineSurveys = group?.onlineSurveys ?? [];

this.canLinkToOnlineSurvey = groupOnlineSurveys.some(survey =>
survey.published &&
survey.formId === this.eventFormDefinition.formId &&
this.eventFormDefinition.allowOnline
);

if (this.canLinkToOnlineSurvey) {
this.surveyLinkUrl = `/releases/prod/online-survey-apps/${this.groupId}/${this.eventFormDefinition.formId}/#/case/event/form/${this.case._id}/${this.caseEvent.id}/${this.eventForm.id}`;
}

this.canUserDeleteForms = ((this.eventFormDefinition.allowDeleteIfFormNotCompleted && !this.eventForm.complete)
|| (this.eventFormDefinition.allowDeleteIfFormNotStarted && !this.eventForm.formResponseId));
const response = await this.formService.getResponse(this.eventForm.formResponseId);
Expand Down Expand Up @@ -131,4 +149,35 @@ export class EventFormListItemComponent implements OnInit {
onUnarchiveFormClick() {
this.formUnarchivedEvent.emit(this.eventForm.id);
}

showLinkMenu() {
this.ref.detectChanges()
}

onCopyLinkClick() {
const url = `${window.location.origin}/${this.surveyLinkUrl}`;
try {
navigator.clipboard.writeText(url);

this.tangyErrorHandler.handleError('Online Survey link copied to clipboard');
} catch (err) {
let errMsg = 'Failed to copy link to clipboard';
if (window.location.origin.startsWith('http://')) {
errMsg = 'Copy to clipboard is not supported with http://.';
}
this.tangyErrorHandler.handleError(errMsg);
}
}

onQRCodeLinkClick() {
const url = `${window.location.origin}${this.surveyLinkUrl}`;

const qr = new qrcode.default(0, 'H')
qr.addData(`${url}`)
qr.make()
window['dialog'].innerHTML = `<div style="width:${Math.round((window.innerWidth > window.innerHeight ? window.innerHeight : window.innerWidth) *.6)}px" id="qr"></div>`
window['dialog'].open()
window['dialog'].querySelector('#qr').innerHTML = qr.createSvgTag({cellSize:500, margin:0,cellColor:(c, r) =>''})
}

}
4 changes: 2 additions & 2 deletions editor/src/app/core/auth/_components/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export class LoginComponent implements OnInit {
if (await this.authenticationService.login(this.user.username, this.user.password)) {
this.router.navigate(['/projects']);
} else {
this.errorMessage = _TRANSLATE('Login Unsuccesful');
this.errorMessage = _TRANSLATE('Login Unsuccessful');
}
} catch (error) {
this.errorMessage = _TRANSLATE('Login Unsuccesful');
this.errorMessage = _TRANSLATE('Login Unsuccessful');
console.error(error);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
<h2>Instructions: </h2>

<div>
In the Unpublished Surveys section, click the
<button class="info-button">
<i class="material-icons tangy-location-list-icon">published_with_changes</i>
</button>
button to "Publish" an online survey. It will then be listed in the Published Surveys section.
</div>

<div>
In the Published Surveys section, use the link
In the <strong>Published Surveys</strong> section, use the link
<button class="info-button">
<i class="material-icons tangy-location-list-icon">link</i>
</button>
Expand All @@ -21,14 +13,40 @@ <h2>Instructions: </h2>
<i class="material-icons tangy-location-list-icon">unpublished</i>
</button>
button to "Un-publish" an online survey.
The
<button class="info-button">
<i class="material-icons tangy-location-list-icon">lock</i>
</button> button appears for surveys that require a Device User and Access Code.
</div>

<div>
In the <strong>Unpublish Surveys</strong> section, click the
<button class="info-button">
<i class="material-icons tangy-location-list-icon">published_with_changes</i>
</button>
button to "Publish" an online survey. It will then be listed in the Published Surveys section.
To 'Publish' a survey and require a Device User to provide an Access Code, click the
<button class="info-button">
<i class="material-icons tangy-location-list-icon">lock</i>
</button> button.
</div>

<div>

</div>

</div>
<h2 class="tangy-foreground-secondary">{{'Published Surveys'|translate}}</h2>
<mat-list class="drag-list">
<mat-list-item class="drag-item" *ngFor="let form of publishedSurveys; let index=index">
<span>{{index+1}}</span>
<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<span>&nbsp;&nbsp;</span>
<span class="tangy-spacer" [innerHTML]="form.title|unsanitizeHtml"></span>
<span *ngIf="form.locked">
<button mat-icon-button class="lock-button">
<i class="material-icons mat-32 tangy-location-list-icon">lock</i>
</button>
</span>
<span>{{form.updatedOn|date :'medium'}}
</span>

Expand All @@ -47,14 +65,15 @@ <h2 class="tangy-foreground-secondary">{{'Unpublished Surveys'|translate}}</h2>
<span>{{index+1}}</span>
<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<span class="tangy-spacer" [innerHTML]="form.title|unsanitizeHtml"></span>

<span >{{form.updatedOn|date :'medium'}}
<span *appHasAPermission="let i;group:group._id; permission:'can_manage_forms'">
<button mat-icon-button (click)="publishSurvey(form.id, form.title)">
<button mat-icon-button (click)="publishSurvey(form.id, form.title, false)">
<i class="material-icons mat-32 tangy-location-list-icon">published_with_changes</i>
</button>
<button mat-icon-button (click)="publishSurvey(form.id, form.title, true)">
<i class="material-icons mat-32 tangy-location-list-icon">lock</i>
</button>
</span>

<span >{{form.updatedOn|date :'medium'}}
</span>
</mat-list-item>
</mat-list>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { TangyErrorHandler } from 'src/app/shared/_services/tangy-error-handler.
import { _TRANSLATE } from 'src/app/shared/_services/translation-marker';
import { GroupsService } from '../services/groups.service';
import { TangerineFormsService } from '../services/tangerine-forms.service';
import { ProcessMonitorService } from 'src/app/shared/_services/process-monitor.service';
import { ProcessMonitorDialogComponent } from 'src/app/shared/_components/process-monitor-dialog/process-monitor-dialog.component';
import { MatDialog } from '@angular/material/dialog';

@Component({
selector: 'app-release-online-survey',
Expand All @@ -19,10 +22,15 @@ export class ReleaseOnlineSurveyComponent implements OnInit {
group;
publishedSurveys;
unPublishedSurveys;
dialogRef:any

constructor(private route: ActivatedRoute,
private groupService: GroupsService,
private errorHandler: TangyErrorHandler,
private tangyFormService: TangerineFormsService) { }
private tangyFormService: TangerineFormsService,
private processMonitorService: ProcessMonitorService,
private dialog: MatDialog,
) { }

async ngOnInit() {
this.groupId = this.route.snapshot.paramMap.get('groupId');
Expand All @@ -32,6 +40,20 @@ export class ReleaseOnlineSurveyComponent implements OnInit {
url: 'onlineSurvey'
}
];
this.processMonitorService.change.subscribe((isDone) => {
if (this.processMonitorService.processes.length === 0) {
this.dialog.closeAll()
} else {
this.dialog.closeAll()
this.dialogRef = this.dialog.open(ProcessMonitorDialogComponent, {
data: {
messages: this.processMonitorService.processes.map(process => process.description).reverse()
},
disableClose: true
})
}
})

await this.getForms();
}

Expand All @@ -46,24 +68,32 @@ export class ReleaseOnlineSurveyComponent implements OnInit {
this.publishedSurveys = surveyData.filter(e => e.published);
this.unPublishedSurveys = surveyData.filter(e => !e.published);
}
async publishSurvey(formId, appName) {
async publishSurvey(formId, appName, locked) {
const process = this.processMonitorService.start('publishSurvey', 'Publishing Survey');

try {
await this.groupService.publishSurvey(this.groupId, formId, 'prod', appName);
await this.groupService.publishSurvey(this.groupId, formId, 'prod', appName, locked);
await this.getForms();
this.errorHandler.handleError(_TRANSLATE('Survey Published Successfully.'));
} catch (error) {
console.error(error);
this.errorHandler.handleError(_TRANSLATE('Could Not Contact Server.'));
} finally {
this.processMonitorService.stop(process.id);
}
}
async unPublishSurvey(formId) {
const process = this.processMonitorService.start('unpublishSurvey', 'Un-publishing Survey');

try {
await this.groupService.unPublishSurvey(this.groupId, formId);
await this.getForms();
this.errorHandler.handleError(_TRANSLATE('Survey UnPublished Successfully.'));
this.errorHandler.handleError(_TRANSLATE('Survey Un-published Successfully.'));
} catch (error) {
console.error(error);
this.errorHandler.handleError(_TRANSLATE('Could Not Contact Server.'));
} finally {
this.processMonitorService.stop(process.id);
}
}

Expand Down
7 changes: 4 additions & 3 deletions editor/src/app/groups/services/groups.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,11 @@ export class GroupsService {
}
}

async publishSurvey(groupId, formId, releaseType = 'prod', appName) {
async publishSurvey(groupId, formId, releaseType = 'prod', appName, locked=false) {
try {
const response = await this.httpClient.post(`/onlineSurvey/publish/${groupId}/${formId}`, {groupId, formId}, {observe: 'response'}).toPromise();
await this.httpClient.get(`/editor/release-online-survey-app/${groupId}/${formId}/${releaseType}/${appName}/${response.body['uploadKey']}`).toPromise()
const response = await this.httpClient.post(`/onlineSurvey/publish/${groupId}/${formId}`, {groupId, formId, locked}, {observe: 'response'}).toPromise();
const uploadKey = response.body['uploadKey']
await this.httpClient.post(`/editor/release-online-survey-app/${groupId}/${formId}/${releaseType}/${appName}`, {uploadKey, locked}).toPromise()
} catch (error) {
this.errorHandler.handleError(_TRANSLATE('Could Not Contact Server.'));
}
Expand Down
7 changes: 6 additions & 1 deletion online-survey-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
"@angular/platform-browser": "~10.1.0",
"@angular/platform-browser-dynamic": "~10.1.0",
"@angular/router": "~10.1.0",
"@ngx-translate/core": "^11.0.1",
"@ngx-translate/http-loader": "^4.0.0",
"@webcomponents/webcomponentsjs": "^2.4.4",
"axios": "^0.21.4",
"fast-json-patch": "^3.1.1",
"jwt-decode": "^4.0.0",
"material-design-icons-iconfont": "^6.1.0",
"redux": "^4.0.5",
"rxjs": "~6.6.0",
Expand All @@ -34,9 +39,9 @@
"@angular-devkit/build-angular": "~0.1001.0",
"@angular/cli": "~10.1.0",
"@angular/compiler-cli": "~10.1.0",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
Expand Down
4 changes: 4 additions & 0 deletions online-survey-app/src/app/app-context.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum AppContext {
Editor = 'EDITOR',
Client = 'CLIENT'
}
Loading

0 comments on commit cc68399

Please sign in to comment.