[ADF-] update library to use new js-api 3.0.0 (#4097)

This commit is contained in:
Eugenio Romano
2019-01-08 16:29:30 +00:00
committed by Eugenio Romano
parent 2acd1b4e26
commit 3ef7d3b7ea
430 changed files with 1966 additions and 2149 deletions
@@ -17,6 +17,7 @@
import { Component, EventEmitter, Input, OnChanges, Output, ViewEncapsulation } from '@angular/core';
import { RatingService } from './services/rating.service';
import { RatingEntry } from 'alfresco-js-api-node';
@Component({
selector: 'adf-like',
@@ -37,16 +38,17 @@ export class LikeComponent implements OnChanges {
ratingType: string = 'likes';
isLike: boolean = false;
constructor(private ratingService: RatingService) {}
constructor(private ratingService: RatingService) {
}
ngOnChanges() {
this.clean();
this.ratingService.getRating(this.nodeId, this.ratingType).subscribe(
(data) => {
if (data.entry.aggregate) {
this.likesCounter = data.entry.aggregate.numberOfRatings;
if (data.entry.ratedAt) {
(ratingEntry: RatingEntry) => {
if (ratingEntry.entry.aggregate) {
this.likesCounter = ratingEntry.entry.aggregate.numberOfRatings;
if (ratingEntry.entry.ratedAt) {
this.isLike = true;
}
}
@@ -65,8 +67,8 @@ export class LikeComponent implements OnChanges {
);
} else {
this.ratingService.postRating(this.nodeId, this.ratingType, true).subscribe(
(data) => {
this.likesCounter = data.entry.aggregate.numberOfRatings;
(ratingEntry: RatingEntry) => {
this.likesCounter = ratingEntry.entry.aggregate.numberOfRatings;
this.isLike = true;
this.changeVote.emit(this.likesCounter);
}
@@ -17,6 +17,7 @@
import { Component, EventEmitter, Input, OnChanges, Output, ViewEncapsulation } from '@angular/core';
import { RatingService } from './services/rating.service';
import { RatingEntry } from '@alfresco/js-api';
@Component({
selector: 'adf-rating',
@@ -47,9 +48,9 @@ export class RatingComponent implements OnChanges {
let ratingObserver = this.ratingService.getRating(this.nodeId, this.ratingType);
ratingObserver.subscribe(
(data) => {
if (data.entry.aggregate) {
this.average = data.entry.aggregate.average;
(ratingEntry: RatingEntry) => {
if (ratingEntry.entry.aggregate) {
this.average = ratingEntry.entry.aggregate.average;
this.calculateStars();
}
}
@@ -63,9 +64,9 @@ export class RatingComponent implements OnChanges {
for (let i = 0; i < 5; i++) {
if (i < this.average) {
this.stars.push({fill: true});
this.stars.push({ fill: true });
} else {
this.stars.push({fill: false});
this.stars.push({ fill: false });
}
}
@@ -74,10 +75,10 @@ export class RatingComponent implements OnChanges {
updateVote(vote: number) {
this.ratingService.postRating(this.nodeId, this.ratingType, vote).subscribe(
(data) => {
if (data.entry.aggregate) {
if (this.average !== data.entry.aggregate.average) {
this.average = data.entry.aggregate.average;
(ratingEntry: RatingEntry) => {
if (ratingEntry.entry.aggregate) {
if (this.average !== ratingEntry.entry.aggregate.average) {
this.average = ratingEntry.entry.aggregate.average;
this.calculateStars();
}
}
@@ -56,7 +56,7 @@ describe('Rating service', () => {
contentType: 'json',
responseText: {
'entry': {
myRating: 1,
myRating: '1',
'ratedAt': '2017-04-06T14:34:28.061+0000',
'id': 'fiveStar',
'aggregate': {'numberOfRatings': 1, 'average': 1.0}
@@ -79,7 +79,7 @@ describe('Rating service', () => {
contentType: 'json',
responseText: {
'entry': {
'myRating': 3,
'myRating': '3',
'ratedAt': '2017-04-06T14:36:40.731+0000',
'id': 'fiveStar',
'aggregate': {'numberOfRatings': 1, 'average': 3.0}
@@ -17,10 +17,10 @@
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { RatingBody } from 'alfresco-js-api';
import { RatingEntry, RatingBody } from '@alfresco/js-api';
import { from, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { Observable } from 'rxjs/internal/Observable';
@Injectable({
providedIn: 'root'
@@ -36,7 +36,7 @@ export class RatingService {
* @param ratingType Type of rating (can be "likes" or "fiveStar")
* @returns The rating value
*/
getRating(nodeId: string, ratingType: any): any {
getRating(nodeId: string, ratingType: any): Observable<RatingEntry | {}> {
return from(this.apiService.getInstance().core.ratingsApi.getRating(nodeId, ratingType))
.pipe(
catchError(this.handleError)
@@ -50,11 +50,11 @@ export class RatingService {
* @param vote Rating value (boolean for "likes", numeric 0..5 for "fiveStar")
* @returns Details about the rating, including the new value
*/
postRating(nodeId: string, ratingType: any, vote: any): any {
let ratingBody: RatingBody = {
postRating(nodeId: string, ratingType: string, vote: any): Observable<RatingEntry | {}> {
let ratingBody: RatingBody = new RatingBody({
'id': ratingType,
'myRating': vote
};
});
return from(this.apiService.getInstance().core.ratingsApi.rate(nodeId, ratingBody))
.pipe(
catchError(this.handleError)
@@ -67,14 +67,14 @@ export class RatingService {
* @param ratingType Type of rating to remove (can be "likes" or "fiveStar")
* @returns Null response indicating that the operation is complete
*/
deleteRating(nodeId: string, ratingType: any): any {
deleteRating(nodeId: string, ratingType: any): Observable<any> {
return from(this.apiService.getInstance().core.ratingsApi.removeRating(nodeId, ratingType))
.pipe(
catchError(this.handleError)
);
}
private handleError(error: Response): any {
private handleError(error: any): any {
console.error(error);
return throwError(error || 'Server error');
}