Skip to content

Commit

Permalink
Merge pull request #777 from HiP-App/iss-hipcms-965
Browse files Browse the repository at this point in the history
iss-hipcms-965 Add view statistics to exhibit view
  • Loading branch information
objectliteral authored Mar 19, 2018
2 parents 3283896 + 8862cf7 commit 6c9662e
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 53 deletions.
11 changes: 11 additions & 0 deletions app/mobile-content/exhibits/shared/exhibit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ export class ExhibitService {
);
}

getExhibitStatistics(id: number) {
return this.mobileContentApiService.getUrl('/api/Exhibits/Statistic/' + id, {})
.toPromise()
.then(
(response: Response) => response.json()
)
.catch(
(error: any) => ExhibitService.handleError(error)
);
}

/**
* Gets the history of changes
* @param id Id of the Exhibit you want to be deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ img {
margin-right: 10px;
}

.float-left {
float: left;
}

.float-right {
float: right;
margin-right: 200px;
}

.right {
width: 40%;
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,28 @@ <h4>{{ 'tags' | translate }}</h4>
<md-chip-list>
<md-chip *ngFor="let tag of tags">{{ tag.title }}</md-chip>
</md-chip-list>
<div *ngIf="rating">
<h4>{{ 'ratings' | translate }}</h4>
<hip-star-rating-table [rating]='rating'></hip-star-rating-table>
<div>
<div *ngIf="rating" class="float-left">
<h4>{{ 'ratings' | translate }}</h4>
<hip-star-rating-table [rating]='rating'></hip-star-rating-table>
</div>
<div *ngIf="statistics" class="float-right">
<h4>{{ 'visits' | translate }}</h4>
<table>
<tr>
<td>{{ 'last day' | translate }}</td>
<td>{{ statistics.day }}</td>
</tr>
<tr>
<td>{{ 'last month' | translate }}</td>
<td>{{ statistics.month }}</td>
</tr>
<tr>
<td>{{ 'last year' | translate }}</td>
<td>{{ statistics.year }}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
Expand Down
110 changes: 62 additions & 48 deletions app/mobile-content/exhibits/view-exhibit/view-exhibit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ export class ViewExhibitComponent implements OnInit {
tags: Tag[] = [];
imageUrl: SafeUrl;
rating: any;
statistics: any;

private deleteDialogRef: MdDialogRef<ConfirmDeleteDialogComponent>;
private changeHistoryDialogRef: MdDialogRef<ChangeHistoryComponent>;

constructor(
constructor(
private route: ActivatedRoute,
private dialog: MdDialog,
private domSanitizer: DomSanitizer,
Expand Down Expand Up @@ -70,6 +71,7 @@ export class ViewExhibitComponent implements OnInit {
this.getTags();
this.getImage();
this.getRating();
this.getStatistics();
})
.catch((error: any) => {
this.toasterService.pop('error', this.translate('Error fetching exhibit'), error);
Expand All @@ -79,27 +81,27 @@ export class ViewExhibitComponent implements OnInit {
deleteExhibit(exhibit: Exhibit) {
let context = this;
this.deleteDialogRef = this.dialog.open(ConfirmDeleteDialogComponent, {
data: {
title: this.translateService.instant('delete exhibit'),
message: this.translateService.instant('confirm delete exhibit', { name: exhibit.name })
}
data: {
title: this.translateService.instant('delete exhibit'),
message: this.translateService.instant('confirm delete exhibit', { name: exhibit.name })
}
});
this.deleteDialogRef.afterClosed().subscribe(
(confirmed: boolean) => {
if (confirmed) {
this.exhibitService.deleteExhibit(exhibit.id)
.then(
() => {
this.toasterService.pop('success', 'Success', exhibit.name + ' - ' + this.translate('exhibit deleted'));
this.router.navigate(['../../'], {relativeTo: this.route});
(confirmed: boolean) => {
if (confirmed) {
this.exhibitService.deleteExhibit(exhibit.id)
.then(
() => {
this.toasterService.pop('success', 'Success', exhibit.name + ' - ' + this.translate('exhibit deleted'));
this.router.navigate(['../../'], { relativeTo: this.route });
}
).catch(
error => this.toasterService.pop('error', this.translate('Error while saving'), error)
);
}
).catch(
error => this.toasterService.pop('error', this.translate('Error while saving'), error)
);
}
}
);
}
}

private getTags() {
for (let tagId of this.exhibit.tags) {
Expand All @@ -123,37 +125,49 @@ export class ViewExhibitComponent implements OnInit {
});
}

private openHistory() {
let context = this;
this.exhibitService.getHistory(this.exhibit.id)
.then(
(response) => {
this.changeHistoryDialogRef = this.dialog.open(ChangeHistoryComponent, { width: '60%',
data: {
title: context.exhibit.name,
data: response
}
});
}
).catch(
(error: any) => {
this.toasterService.pop('error', this.translate('Error fetching history') , error);
}
);
}

private getRating() {
this.exhibitService.getExhibitRating(this.exhibit.id)
.then(
(response) => {
this.rating = response;
}
).catch(
(error: any) => {
this.toasterService.pop('error', this.translate('Error fetching ratings') , error);
}
);
}
private openHistory() {
let context = this;
this.exhibitService.getHistory(this.exhibit.id)
.then(
(response) => {
this.changeHistoryDialogRef = this.dialog.open(ChangeHistoryComponent, {
width: '60%',
data: {
title: context.exhibit.name,
data: response
}
});
}
).catch(
(error: any) => {
this.toasterService.pop('error', this.translate('Error fetching history'), error);
}
);
}

private getRating() {
this.exhibitService.getExhibitRating(this.exhibit.id)
.then(
(response) => {
this.rating = response;
}
).catch(
(error: any) => {
this.toasterService.pop('error', this.translate('Error fetching ratings'), error);
}
);
}

private getStatistics() {
this.exhibitService.getExhibitStatistics(this.exhibit.id)
.then(
(response) => this.statistics = response
)
.catch(
(error: any) => this.toasterService.pop('error', this.translate('Error fetching statistic'), error)
);
}


private translate(data: string): string {
let translatedResponse: string;
Expand Down
6 changes: 5 additions & 1 deletion i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -506,5 +506,9 @@
"error deleting question": "Fehler beim Löschen der Frage",
"success deleting question": "Frage erfolgreich gelöscht",
"delete question": "Frage löschen",
"confirm delete question": "Möchten Sie die Frage „{{name}}“ löschen?"
"confirm delete question": "Möchten Sie die Frage „{{name}}“ löschen?",
"visits": "Besuche",
"last day": "Letzter Tag",
"last month": "Letzter Monat",
"last year": "Letztes Jahr"
}
6 changes: 5 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,5 +412,9 @@
"error deleting question": "Error while deleting question",
"success deleting question": "Successfully deleted question",
"delete question": "Delete question",
"confirm delete question": "Do you want to delete the question „{{name}}“?"
"confirm delete question": "Do you want to delete the question „{{name}}“?",
"visits": "Visits",
"last day": "Last day",
"last month": "Last month",
"last year": "Last year"
}

0 comments on commit 6c9662e

Please sign in to comment.