[ACS-5572] Remove unused Social components (#8758)

* ACS-5572 Remove unused Social components

* [ACS-5572] revert wrong file deletion
This commit is contained in:
Grzegorz Jaśkowski
2024-04-15 15:39:32 +02:00
committed by GitHub
parent 0db32ef10f
commit 22da251c02
23 changed files with 0 additions and 1113 deletions

View File

@@ -22,7 +22,6 @@ import { CoreModule, SearchTextModule, provideTranslations } from '@alfresco/adf
import { MaterialModule } from './material.module';
import { SocialModule } from './social/social.module';
import { TagModule } from './tag/tag.module';
import { WebScriptModule } from './webscript/webscript.module';
import { DocumentListModule } from './document-list/document-list.module';
@@ -58,7 +57,6 @@ import { ContentAuthLoaderService } from './auth-loader/content-auth-loader.serv
imports: [
ContentPipeModule,
CoreModule,
SocialModule,
TagModule,
CommonModule,
WebScriptModule,
@@ -95,7 +93,6 @@ import { ContentAuthLoaderService } from './auth-loader/content-auth-loader.serv
],
exports: [
ContentPipeModule,
SocialModule,
TagModule,
WebScriptModule,
DocumentListModule,

View File

@@ -1,18 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './public-api';

View File

@@ -1,13 +0,0 @@
<div id="adf-like-container" class="adf-like-container">
<div class="adf-like">
<span id="adf-like-{{nodeId}}" [ngClass]="{'adf-like-select': isLike ,'adf-like-grey': !isLike }"
(click)="likeClick()">
<mat-icon>thumb_up</mat-icon>
</span>
</div>
<div class="adf-like-counter-container">
<div id="adf-like-counter" class="adf-like-counter">{{likesCounter}}</div>
<div class="adf-left" *ngIf="likesCounter===1">Like</div>
<div class="adf-left" *ngIf="likesCounter!==1">Likes</div>
</div>
</div>

View File

@@ -1,34 +0,0 @@
.adf-like-container {
display: flex;
overflow: hidden;
width: 100%;
align-items: center;
margin-top: 13px;
.adf-like-counter-container {
display: inherit;
padding: 0 6px;
}
.adf-left {
padding: 0 6px;
}
.adf-like-select {
cursor: pointer;
color: #2196f3;
&:hover {
color: #808080;
}
}
.adf-like-grey {
cursor: pointer;
color: #808080;
&:hover {
color: #2196f3;
}
}
}

View File

@@ -1,92 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LikeComponent } from './like.component';
import { ContentTestingModule } from '../testing/content.testing.module';
import { of } from 'rxjs';
import { RatingService } from './services/rating.service';
describe('Like component', () => {
let component: any;
let fixture: ComponentFixture<LikeComponent>;
let element: HTMLElement;
let service: RatingService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ContentTestingModule]
});
service = TestBed.inject(RatingService);
spyOn(service, 'getRating').and.returnValue(
of({
entry: {
id: 'likes',
aggregate: { numberOfRatings: 2 }
}
})
);
fixture = TestBed.createComponent(LikeComponent);
element = fixture.nativeElement;
component = fixture.componentInstance;
component.nodeId = 'test-id';
component.ngOnChanges();
fixture.detectChanges();
});
it('should load the likes by default on onChanges', async () => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#adf-like-counter').innerHTML).toBe('2');
});
it('should increase the number of likes when clicked', async () => {
spyOn(service, 'postRating').and.returnValue(
of({
entry: {
id: 'likes',
aggregate: { numberOfRatings: 3 }
}
})
);
const likeButton: any = element.querySelector('#adf-like-test-id');
likeButton.click();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#adf-like-counter').innerHTML).toBe('3');
});
it('should decrease the number of likes when clicked and is already liked', async () => {
spyOn(service, 'deleteRating').and.returnValue(of(''));
component.isLike = true;
const likeButton: any = element.querySelector('#adf-like-test-id');
likeButton.click();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#adf-like-counter').innerHTML).toBe('1');
});
});

View File

@@ -1,56 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Meta, moduleMetadata, Story } from '@storybook/angular';
import { RatingService } from './services/rating.service';
import { LikeComponent } from './like.component';
import { RatingServiceMock } from './mock/rating.service.mock';
import { SocialModule } from './social.module';
export default {
component: LikeComponent,
title: 'Content Services/Social/Like',
decorators: [
moduleMetadata({
imports: [SocialModule],
providers: [
{ provide: RatingService, useClass: RatingServiceMock }
]
})
],
argTypes: {
nodeId: {
control: 'text',
description: 'Identifier of a node to apply likes to.',
defaultValue:'fake-like-node-id',
table: {
type: { summary: 'string' }
}
},
changeVote: {
action: 'changeVote',
description: 'Emitted when the "vote" gets changed.',
table: { category: 'Actions' }
}
}
} as Meta;
const template: Story<LikeComponent> = (args: LikeComponent) => ({
props: args
});
export const like = template.bind({});

View File

@@ -1,86 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, EventEmitter, Input, OnChanges, Output, ViewEncapsulation } from '@angular/core';
import { RatingService } from './services/rating.service';
import { RatingEntry } from '@alfresco/js-api';
/**
* @deprecated Like component is not used in ACA/ADW/ACC, can be removed.
*/
@Component({
selector: 'adf-like',
styleUrls: ['./like.component.scss'],
templateUrl: './like.component.html',
encapsulation: ViewEncapsulation.None
})
export class LikeComponent implements OnChanges {
/** Identifier of a node to apply likes to. */
@Input()
nodeId: string;
/** Emitted when the "vote" gets changed. */
@Output()
changeVote = new EventEmitter();
likesCounter: number = 0;
ratingType: string = 'likes';
isLike: boolean = false;
constructor(private ratingService: RatingService) {
}
ngOnChanges() {
this.clean();
this.ratingService.getRating(this.nodeId, this.ratingType).subscribe(
(ratingEntry: RatingEntry) => {
if (ratingEntry.entry.aggregate) {
this.likesCounter = ratingEntry.entry.aggregate.numberOfRatings;
if (ratingEntry.entry.ratedAt) {
this.isLike = true;
}
}
}
);
}
likeClick() {
if (this.isLike) {
this.ratingService.deleteRating(this.nodeId, this.ratingType).subscribe(
() => {
this.likesCounter -= 1;
this.isLike = false;
this.changeVote.emit(this.likesCounter);
}
);
} else {
this.ratingService.postRating(this.nodeId, this.ratingType, true).subscribe(
(ratingEntry: RatingEntry) => {
this.likesCounter = ratingEntry.entry.aggregate.numberOfRatings;
this.isLike = true;
this.changeVote.emit(this.likesCounter);
}
);
}
}
clean() {
this.isLike = false;
this.likesCounter = 0;
}
}

View File

@@ -1,34 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const ratingOneMock = {
entry: {
myRating: '1',
ratedAt: '2017-04-06T14:34:28.061+0000',
id: 'fiveStar',
aggregate: {numberOfRatings: 1, average: 1.0}
}
};
export const ratingThreeMock = {
entry: {
myRating: '3',
ratedAt: '2017-04-06T14:36:40.731+0000',
id: 'fiveStar',
aggregate: {numberOfRatings: 1, average: 3.0}
}
};

View File

@@ -1,60 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Injectable } from '@angular/core';
import { RatingEntry } from '@alfresco/js-api';
import { Observable, of } from 'rxjs';
import { ratingOneMock, ratingThreeMock } from './rating-response.mock';
import { RatingServiceInterface } from '../services/rating.service.interface';
@Injectable({
providedIn: 'root'
})
export class RatingServiceMock implements RatingServiceInterface {
getRating(nodeId: string, _ratingType: any): Observable<RatingEntry | any> {
if (nodeId === 'fake-like-node-id') {
return of(ratingOneMock);
}
return of(ratingThreeMock);
}
postRating(nodeId: string, _ratingType: string, _vote: any): Observable<RatingEntry | any> {
if (nodeId === 'ratingOneMock') {
ratingOneMock.entry.aggregate.numberOfRatings = 1;
ratingOneMock.entry.aggregate.average = 1.0;
return of(ratingOneMock);
}
ratingThreeMock.entry.aggregate.numberOfRatings = 1;
ratingThreeMock.entry.aggregate.average = 1.0;
return of(ratingThreeMock);
}
deleteRating(nodeId: string, _ratingType: any): Observable<any> {
if (nodeId === 'ratingOneMock') {
ratingOneMock.entry.aggregate.numberOfRatings = 0;
ratingOneMock.entry.aggregate.average = 0;
return of(ratingOneMock);
}
ratingThreeMock.entry.aggregate.numberOfRatings = 0;
ratingThreeMock.entry.aggregate.average = 0;
return of(ratingThreeMock);
}
}

View File

@@ -1,23 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './rating.component';
export * from './like.component';
export * from './services/rating.service';
export * from './social.module';

View File

@@ -1,18 +0,0 @@
<mat-list id="adf-rating-container" class="adf-rating-container">
<mat-list-item class="adf-rating-star" *ngFor="let currentRate of stars; let idx = index;">
<span id="adf-rate-{{idx}}">
<mat-icon id="adf-colored-star-{{idx}}" *ngIf="currentRate.fill" class="adf-colored-star"
[ngClass]="{'adf-average-star': !ratingValue}"
(click)="updateVote(idx + 1)">star_rate
</mat-icon>
<mat-icon id="adf-grey-star-{{idx}}" *ngIf="!currentRate.fill" class="adf-grey-star"
(click)="updateVote(idx + 1)">star_border
</mat-icon>
</span>
</mat-list-item>
<div class="adf-rating-counter-container">
<div id="adf-rating-counter" class="adf-rating-counter">{{ratingsCounter}}</div>
<div class="adf-rating-left" *ngIf="ratingsCounter<=1">Rating</div>
<div class="adf-rating-left" *ngIf="ratingsCounter>1">Ratings</div>
</div>
</mat-list>

View File

@@ -1,49 +0,0 @@
$adf-rated-star-color: #ffe944;
$adf-average-star-color: #808080;
.adf-rating-container {
display: flex;
overflow: hidden;
width: 100%;
.adf-rating-counter-container {
display: flex;
align-items: center;
padding: 0 6px;
}
.adf-rating-left {
padding: 0 6px;
}
.adf-rating-star {
display: flex;
justify-content: center;
transition: all 0.3s;
cursor: pointer;
width: 25px;
&:hover {
transform: rotate(13deg) scale(1.2);
}
}
.adf-colored-star {
color: $adf-rated-star-color;
}
.adf-colored-star.adf-grey-star,
.adf-colored-star.adf-average-star {
color: $adf-average-star-color;
}
}
[dir='rtl'] .adf-rating-container {
.adf-rating-star {
transform: rotate(145deg);
}
.adf-rating-star:hover {
transform: rotate(158deg) scale(1.2);
}
}

View File

@@ -1,151 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RatingComponent } from './rating.component';
import { ContentTestingModule } from '../testing/content.testing.module';
import { of } from 'rxjs';
import { RatingService } from './services/rating.service';
describe('Rating component', () => {
let component: any;
let fixture: ComponentFixture<RatingComponent>;
let element: HTMLElement;
let service: RatingService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ContentTestingModule]
});
fixture = TestBed.createComponent(RatingComponent);
service = TestBed.inject(RatingService);
element = fixture.nativeElement;
component = fixture.componentInstance;
component.nodeId = 'test-id';
fixture.detectChanges();
});
afterEach(() => {
fixture.destroy();
});
describe('Rendering tests', () => {
it('should rating component should be present', async () => {
spyOn(service, 'getRating').and.returnValue(
of({
entry: {
id: 'fiveStar',
aggregate: {
numberOfRatings: 1,
average: 4
}
}
})
);
component.ngOnChanges();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#adf-rating-container')).not.toBe(null);
});
it('should the star rating filled with the right grey/colored star', async () => {
spyOn(service, 'getRating').and.returnValue(
of({
entry: {
myRating: 3,
ratedAt: '2017-04-06T14:34:28.061+0000',
id: 'fiveStar',
aggregate: { numberOfRatings: 1, average: 3.0 }
}
})
);
component.ngOnChanges();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelectorAll('.adf-colored-star').length).toBe(3);
expect(element.querySelectorAll('.adf-grey-star').length).toBe(2);
});
});
it('should click on a star to change your vote', async () => {
spyOn(service, 'getRating').and.returnValue(
of({
entry: {
myRating: 1,
ratedAt: '2017-04-06T14:34:28.061+0000',
id: 'fiveStar',
aggregate: { numberOfRatings: 1, average: 1.0 }
}
})
);
const rateSpy = spyOn(service, 'postRating').and.returnValue(
of({
entry: {
myRating: 3,
ratedAt: '2017-04-06T14:36:40.731+0000',
id: 'fiveStar',
aggregate: { numberOfRatings: 1, average: 3.0 }
}
})
);
component.ngOnChanges();
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelectorAll('.adf-colored-star').length).toBe(1);
const starThree: any = element.querySelector('#adf-grey-star-2');
starThree.click();
fixture.detectChanges();
await fixture.whenStable();
expect(rateSpy).toHaveBeenCalled();
expect(element.querySelectorAll('.adf-colored-star').length).toBe(3);
});
it('should click on the rated star to remove your vote', () => {
spyOn(service, 'getRating').and.returnValue(
of({
entry: {
myRating: 3,
ratedAt: '2017-04-06T14:34:28.061+0000',
id: 'fiveStar',
aggregate: { numberOfRatings: 1, average: 3.0 }
}
})
);
spyOn(service, 'deleteRating').and.returnValue(of({}));
component.ngOnChanges();
fixture.detectChanges();
const starThree: any = element.querySelector('#adf-colored-star-2');
starThree.click();
expect(element.querySelectorAll('.adf-colored-star').length).toBe(3);
expect(service.deleteRating).toHaveBeenCalled();
});
});

View File

@@ -1,124 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, EventEmitter, Input, OnChanges, OnDestroy, Output, ViewEncapsulation } from '@angular/core';
import { RatingService } from './services/rating.service';
import { RatingEntry } from '@alfresco/js-api';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
/**
* @deprecated Rating component is not used in ACA/ADW/ACC, can be removed.
*/
@Component({
selector: 'adf-rating',
styleUrls: ['./rating.component.scss'],
templateUrl: './rating.component.html',
encapsulation: ViewEncapsulation.None
})
export class RatingComponent implements OnChanges, OnDestroy {
/** Identifier of the node to apply the rating to. */
@Input()
nodeId: string;
average: number = 0;
ratingsCounter = 0;
ratingType: string = 'fiveStar';
ratingValue: number;
/** Emitted when the "vote" gets changed. */
@Output()
changeVote = new EventEmitter();
stars: Array<any> = [];
onDestroy$ = new Subject<boolean>();
constructor(private ratingService: RatingService) {
}
ngOnChanges() {
this.ratingService.getRating(this.nodeId, this.ratingType)
.pipe(takeUntil(this.onDestroy$))
.subscribe(
(ratingEntry: RatingEntry) => {
this.refreshRating(ratingEntry);
}
);
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
calculateStars() {
this.stars = [];
const roundedAverage = Math.round(this.average);
for (let i = 0; i < 5; i++) {
if (i < roundedAverage) {
this.stars.push({fill: true});
} else {
this.stars.push({fill: false});
}
}
}
updateVote(vote: number) {
if (this.ratingValue === vote) {
this.unRateItem();
} else {
this.rateItem(vote);
}
}
rateItem(vote: number) {
this.ratingService.postRating(this.nodeId, this.ratingType, vote)
.pipe(takeUntil(this.onDestroy$))
.subscribe(
(ratingEntry: RatingEntry) => {
this.refreshRating(ratingEntry);
}
);
}
unRateItem() {
this.ratingService.deleteRating(this.nodeId, this.ratingType).subscribe(
() => {
this.ratingService.getRating(this.nodeId, this.ratingType)
.pipe(takeUntil(this.onDestroy$))
.subscribe(
(ratingEntry: RatingEntry) => {
this.refreshRating(ratingEntry);
}
);
});
}
refreshRating(ratingEntry: RatingEntry) {
this.ratingValue = Number.parseFloat(ratingEntry.entry.myRating);
this.average = ratingEntry.entry.aggregate.average;
this.ratingsCounter = ratingEntry.entry.aggregate.numberOfRatings;
this.calculateStars();
this.changeVote.emit(this.average);
}
}

View File

@@ -1,26 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { RatingEntry } from '@alfresco/js-api';
import { Observable } from 'rxjs';
export interface RatingServiceInterface {
getRating(nodeId: string, ratingType: any): Observable<RatingEntry | any>;
postRating(nodeId: string, ratingType: string, vote: any): Observable<RatingEntry | any>;
deleteRating(nodeId: string, ratingType: any): Observable<any>;
}

View File

@@ -1,74 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { TestBed } from '@angular/core/testing';
import { RatingService } from './rating.service';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { ratingOneMock, ratingThreeMock } from '../mock/rating-response.mock';
declare let jasmine: any;
describe('Rating service', () => {
let service: RatingService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ContentTestingModule]
});
service = TestBed.inject(RatingService);
});
beforeEach(() => {
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('Should get rating return an Observable', (done) => {
const ratingType: string = 'fiveStar';
const nodeId: string = 'fake-node-id';
service.getRating(nodeId, ratingType).subscribe((data) => {
expect(data.entry.myRating).toBe('1');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: ratingOneMock
});
});
it('Should post rating return an Observable', (done) => {
const ratingType: string = 'fiveStar';
const nodeId: string = 'fake-node-id';
service.postRating(nodeId, ratingType, 3).subscribe((data) => {
expect(data.entry.myRating).toBe('3');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: ratingThreeMock
});
});
});

View File

@@ -1,73 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { RatingEntry, RatingBody, RatingsApi } from '@alfresco/js-api';
import { from, Observable } from 'rxjs';
import { RatingServiceInterface } from './rating.service.interface';
@Injectable({
providedIn: 'root'
})
export class RatingService implements RatingServiceInterface {
private _ratingsApi: RatingsApi;
get ratingsApi(): RatingsApi {
this._ratingsApi = this._ratingsApi ?? new RatingsApi(this.apiService.getInstance());
return this._ratingsApi;
}
constructor(private apiService: AlfrescoApiService) {}
/**
* Gets the current user's rating for a node.
*
* @param nodeId Node to get the rating from
* @param ratingType Type of rating (can be "likes" or "fiveStar")
* @returns The rating value
*/
getRating(nodeId: string, ratingType: any): Observable<RatingEntry | any> {
return from(this.ratingsApi.getRating(nodeId, ratingType));
}
/**
* Adds the current user's rating for a node.
*
* @param nodeId Target node for the rating
* @param ratingType Type of rating (can be "likes" or "fiveStar")
* @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: string, vote: any): Observable<RatingEntry | any> {
const ratingBody: RatingBody = {
id: ratingType,
myRating: vote
};
return from(this.ratingsApi.createRating(nodeId, ratingBody));
}
/**
* Removes the current user's rating for a node.
*
* @param nodeId Target node
* @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): Observable<any> {
return from(this.ratingsApi.deleteRating(nodeId, ratingType));
}
}

View File

@@ -1,42 +0,0 @@
/*!
* @license
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { MaterialModule } from '../material.module';
import { LikeComponent } from './like.component';
import { RatingComponent } from './rating.component';
/**
* @deprecated This module uses Like and Rating components are not used in ACA/ADW/ACC and can be removed.
*/
@NgModule({
imports: [
CommonModule,
MaterialModule
],
exports: [
RatingComponent,
LikeComponent
],
declarations: [
RatingComponent,
LikeComponent
]
})
export class SocialModule {}

View File

@@ -16,7 +16,6 @@
*/
export * from './lib/directives/index';
export * from './lib/social/index';
export * from './lib/tag/index';
export * from './lib/webscript/index';
export * from './lib/document-list/index';