mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[ACS-5572] Remove unused Social components (#8758)
* ACS-5572 Remove unused Social components * [ACS-5572] revert wrong file deletion
This commit is contained in:
parent
0db32ef10f
commit
22da251c02
@ -285,10 +285,8 @@ for more information about installing and using the source code.
|
|||||||
| [Document List component](content-services/components/document-list.component.md) | Displays the documents from a repository. | [Source](../lib/content-services/src/lib/document-list/components/document-list.component.ts) |
|
| [Document List component](content-services/components/document-list.component.md) | Displays the documents from a repository. | [Source](../lib/content-services/src/lib/document-list/components/document-list.component.ts) |
|
||||||
| [Dropdown Breadcrumb Component](content-services/components/dropdown-breadcrumb.component.md) | Indicates the current position within a navigation hierarchy using a dropdown menu. | [Source](../lib/content-services/src/lib/breadcrumb/dropdown-breadcrumb.component.ts) |
|
| [Dropdown Breadcrumb Component](content-services/components/dropdown-breadcrumb.component.md) | Indicates the current position within a navigation hierarchy using a dropdown menu. | [Source](../lib/content-services/src/lib/breadcrumb/dropdown-breadcrumb.component.ts) |
|
||||||
| [File Uploading Dialog Component](content-services/components/file-uploading-dialog.component.md) | Shows a dialog listing all the files uploaded with the Upload Button or Drag Area components. | [Source](../lib/content-services/src/lib/upload/components/file-uploading-dialog.component.ts) |
|
| [File Uploading Dialog Component](content-services/components/file-uploading-dialog.component.md) | Shows a dialog listing all the files uploaded with the Upload Button or Drag Area components. | [Source](../lib/content-services/src/lib/upload/components/file-uploading-dialog.component.ts) |
|
||||||
| [Like component](content-services/components/like.component.md) | Allows a user to add "likes" to an item. | [Source](../lib/content-services/src/lib/social/like.component.ts) |
|
|
||||||
| [Node Comments Component](content-services/components/node-comments.component.md) | Displays comments from users involved in a specified content and allows an involved user to add a comment to a content. | [Source](../lib/content-services/src/lib/node-comments/node-comments.component.ts) |
|
| [Node Comments Component](content-services/components/node-comments.component.md) | Displays comments from users involved in a specified content and allows an involved user to add a comment to a content. | [Source](../lib/content-services/src/lib/node-comments/node-comments.component.ts) |
|
||||||
| [Permission List Component](content-services/components/permission-list.component.md) | Shows node permissions as a table. | [Source](../lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.ts) |
|
| [Permission List Component](content-services/components/permission-list.component.md) | Shows node permissions as a table. | [Source](../lib/content-services/src/lib/permission-manager/components/permission-list/permission-list.component.ts) |
|
||||||
| [Rating component](content-services/components/rating.component.md) | Allows a user to add and remove rating to an item. | [Source](../lib/content-services/src/lib/social/rating.component.ts) |
|
|
||||||
| [Search check list component](content-services/components/search-check-list.component.md) | Implements a checklist widget for the Search Filter component. | [Source](../lib/content-services/src/lib/search/components/search-check-list/search-check-list.component.ts) |
|
| [Search check list component](content-services/components/search-check-list.component.md) | Implements a checklist widget for the Search Filter component. | [Source](../lib/content-services/src/lib/search/components/search-check-list/search-check-list.component.ts) |
|
||||||
| [Search Chip Input Component](content-services/components/search-chip-input.component.md) | Displays input for providing phrases display as "chips". | [Source](../lib/content-services/src/lib/search/components/search-chip-input/search-chip-input.component.ts) |
|
| [Search Chip Input Component](content-services/components/search-chip-input.component.md) | Displays input for providing phrases display as "chips". | [Source](../lib/content-services/src/lib/search/components/search-chip-input/search-chip-input.component.ts) |
|
||||||
| [Search Chip Autocomplete Input component](content-services/components/search-chip-autocomplete-input.component.md) | Displays an input with autocomplete options. | [Source](../lib/content-services/src/lib/search/components/search-chip-autocomplete-input/search-chip-autocomplete-input.component.ts) |
|
| [Search Chip Autocomplete Input component](content-services/components/search-chip-autocomplete-input.component.md) | Displays an input with autocomplete options. | [Source](../lib/content-services/src/lib/search/components/search-chip-autocomplete-input/search-chip-autocomplete-input.component.ts) |
|
||||||
@ -395,7 +393,6 @@ for more information about installing and using the source code.
|
|||||||
| [Node Comments Service](content-services/services/node-comments.service.md) | Adds and retrieves comments for nodes in Content Services. | [Source](../lib/content-services/src/lib/node-comments/services/node-comments.service.ts) |
|
| [Node Comments Service](content-services/services/node-comments.service.md) | Adds and retrieves comments for nodes in Content Services. | [Source](../lib/content-services/src/lib/node-comments/services/node-comments.service.ts) |
|
||||||
| [Node permission dialog service](content-services/services/node-permission-dialog.service.md) | Displays dialogs to let the user set node permissions. | [Source](../lib/content-services/src/lib/permission-manager/services/node-permission-dialog.service.ts) |
|
| [Node permission dialog service](content-services/services/node-permission-dialog.service.md) | Displays dialogs to let the user set node permissions. | [Source](../lib/content-services/src/lib/permission-manager/services/node-permission-dialog.service.ts) |
|
||||||
| [Node Permission service](content-services/services/node-permission.service.md) | Manages role permissions for content nodes. | [Source](../lib/content-services/src/lib/permission-manager/services/node-permission.service.ts) |
|
| [Node Permission service](content-services/services/node-permission.service.md) | Manages role permissions for content nodes. | [Source](../lib/content-services/src/lib/permission-manager/services/node-permission.service.ts) |
|
||||||
| [Rating service](content-services/services/rating.service.md) | Manages ratings for items in Content Services. | [Source](../lib/content-services/src/lib/social/services/rating.service.ts) |
|
|
||||||
| [Search filter service](content-services/services/search-filter.service.md) | Registers widgets for use with the Search Filter component. | [Source](../lib/content-services/src/lib/search/services/search-filter.service.ts) |
|
| [Search filter service](content-services/services/search-filter.service.md) | Registers widgets for use with the Search Filter component. | [Source](../lib/content-services/src/lib/search/services/search-filter.service.ts) |
|
||||||
| [Search Query Builder service](content-services/services/search-query-builder.service.md) | Stores information from all the custom search and faceted search widgets, compiles and runs the final search query. | [Source](../lib/content-services/src/lib/search/services/search-query-builder.service.ts) |
|
| [Search Query Builder service](content-services/services/search-query-builder.service.md) | Stores information from all the custom search and faceted search widgets, compiles and runs the final search query. | [Source](../lib/content-services/src/lib/search/services/search-query-builder.service.ts) |
|
||||||
| [Security Controls service](content-services/services/security-controls.service.md) | Manages security groups & marks in Content Services. | [Source](../lib/content-services/src/lib/security/services/security-controls-groups-marks-security.service.ts) |
|
| [Security Controls service](content-services/services/security-controls.service.md) | Manages security groups & marks in Content Services. | [Source](../lib/content-services/src/lib/security/services/security-controls-groups-marks-security.service.ts) |
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
---
|
|
||||||
Title: Like component
|
|
||||||
Added: v2.0.0
|
|
||||||
Status: Active
|
|
||||||
Last reviewed: 2018-11-14
|
|
||||||
---
|
|
||||||
|
|
||||||
# [Like component](../../../lib/content-services/src/lib/social/like.component.ts "Defined in like.component.ts")
|
|
||||||
|
|
||||||
Allows a user to add "likes" to an item.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Basic Usage
|
|
||||||
|
|
||||||
```html
|
|
||||||
<adf-like [nodeId]="nodeId"></adf-like>
|
|
||||||
```
|
|
||||||
|
|
||||||
## Class members
|
|
||||||
|
|
||||||
### Properties
|
|
||||||
|
|
||||||
| Name | Type | Default value | Description |
|
|
||||||
| ---- | ---- | ------------- | ----------- |
|
|
||||||
| nodeId | `string` | | Identifier of a node to apply likes to. |
|
|
||||||
|
|
||||||
### Events
|
|
||||||
|
|
||||||
| Name | Type | Description |
|
|
||||||
| ---- | ---- | ----------- |
|
|
||||||
| changeVote | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<any>` | Emitted when the "vote" gets changed. |
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [Rating component](rating.component.md)
|
|
||||||
- [Rating service](../services/rating.service.md)
|
|
@ -1,48 +0,0 @@
|
|||||||
---
|
|
||||||
Title: Rating component
|
|
||||||
Added: v2.0.0
|
|
||||||
Status: Active
|
|
||||||
Last reviewed: 2019-01-14
|
|
||||||
---
|
|
||||||
|
|
||||||
# [Rating component](../../../lib/content-services/src/lib/social/rating.component.ts "Defined in rating.component.ts")
|
|
||||||
|
|
||||||
Allows a user to add and remove rating to an item.
|
|
||||||
|
|
||||||
It displays the average rating and the number of ratings. If the user has not rated the item the average rating stars color is grey.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
If the user has rated the item the average rating stars color is yellow.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
In order to remove the rating the user should click on the same star that he rated.
|
|
||||||
If the average is decimal number it will be rounded.
|
|
||||||
|
|
||||||
## Basic Usage
|
|
||||||
|
|
||||||
```html
|
|
||||||
<adf-rating
|
|
||||||
[nodeId]="'74cd8a96-8a21-47e5-9b3b-a1b3e296787d'">
|
|
||||||
</adf-rating>
|
|
||||||
```
|
|
||||||
|
|
||||||
## Class members
|
|
||||||
|
|
||||||
### Properties
|
|
||||||
|
|
||||||
| Name | Type | Default value | Description |
|
|
||||||
| ---- | ---- | ------------- | ----------- |
|
|
||||||
| nodeId | `string` | | Identifier of the node to apply the rating to. |
|
|
||||||
|
|
||||||
### Events
|
|
||||||
|
|
||||||
| Name | Type | Description |
|
|
||||||
| ---- | ---- | ----------- |
|
|
||||||
| changeVote | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<any>` | Emitted when the "vote" gets changed. |
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [Like component](like.component.md)
|
|
||||||
- [Rating service](../services/rating.service.md)
|
|
@ -1,48 +0,0 @@
|
|||||||
---
|
|
||||||
Title: Rating service
|
|
||||||
Added: v2.0.0
|
|
||||||
Status: Active
|
|
||||||
Last reviewed: 2018-05-04
|
|
||||||
---
|
|
||||||
|
|
||||||
# [Rating service](../../../lib/content-services/src/lib/social/services/rating.service.ts "Defined in rating.service.ts")
|
|
||||||
|
|
||||||
Manages ratings for items in Content Services.
|
|
||||||
|
|
||||||
## Class members
|
|
||||||
|
|
||||||
### Methods
|
|
||||||
|
|
||||||
- **deleteRating**(nodeId: `string`, ratingType: `any`): [`Observable`](http://reactivex.io/documentation/observable.html)`<any>`<br/>
|
|
||||||
Removes the current user's rating for a node.
|
|
||||||
- _nodeId:_ `string` - Target node
|
|
||||||
- _ratingType:_ `any` - Type of rating to remove (can be "likes" or "fiveStar")
|
|
||||||
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<any>` - Null response indicating that the operation is complete
|
|
||||||
- **getRating**(nodeId: `string`, ratingType: `any`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`RatingEntry`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/RatingEntry.md)`|any>`<br/>
|
|
||||||
Gets the current user's rating for a node.
|
|
||||||
- _nodeId:_ `string` - Node to get the rating from
|
|
||||||
- _ratingType:_ `any` - Type of rating (can be "likes" or "fiveStar")
|
|
||||||
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`RatingEntry`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/RatingEntry.md)`|any>` - The rating value
|
|
||||||
- **postRating**(nodeId: `string`, ratingType: `string`, vote: `any`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`RatingEntry`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/RatingEntry.md)`|any>`<br/>
|
|
||||||
Adds the current user's rating for a node.
|
|
||||||
- _nodeId:_ `string` - Target node for the rating
|
|
||||||
- _ratingType:_ `string` - Type of rating (can be "likes" or "fiveStar")
|
|
||||||
- _vote:_ `any` - Rating value (boolean for "likes", numeric 0..5 for "fiveStar")
|
|
||||||
- **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`RatingEntry`](https://github.com/Alfresco/alfresco-js-api/blob/develop/src/api/content-rest-api/docs/RatingEntry.md)`|any>` - Details about the rating, including the new value
|
|
||||||
|
|
||||||
## Details
|
|
||||||
|
|
||||||
The `ratingType` string currently has two possible options, "likes"
|
|
||||||
and "fiveStar". When the "likes" scheme is used, the result of
|
|
||||||
`getRating` and the `vote` parameter of `postRating` are boolean
|
|
||||||
values. When "fiveStar" is used, the value is an integer representing
|
|
||||||
the number of stars out of five.
|
|
||||||
|
|
||||||
See the [Ratings API](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/RatingsApi.md)
|
|
||||||
in the Alfresco JS API for more information about the returned data and the
|
|
||||||
REST API that this service is based on.
|
|
||||||
|
|
||||||
## See also
|
|
||||||
|
|
||||||
- [Like component](../components/like.component.md)
|
|
||||||
- [Rating component](../components/rating.component.md)
|
|
@ -22,7 +22,6 @@ import { CoreModule, SearchTextModule, provideTranslations } from '@alfresco/adf
|
|||||||
|
|
||||||
import { MaterialModule } from './material.module';
|
import { MaterialModule } from './material.module';
|
||||||
|
|
||||||
import { SocialModule } from './social/social.module';
|
|
||||||
import { TagModule } from './tag/tag.module';
|
import { TagModule } from './tag/tag.module';
|
||||||
import { WebScriptModule } from './webscript/webscript.module';
|
import { WebScriptModule } from './webscript/webscript.module';
|
||||||
import { DocumentListModule } from './document-list/document-list.module';
|
import { DocumentListModule } from './document-list/document-list.module';
|
||||||
@ -58,7 +57,6 @@ import { ContentAuthLoaderService } from './auth-loader/content-auth-loader.serv
|
|||||||
imports: [
|
imports: [
|
||||||
ContentPipeModule,
|
ContentPipeModule,
|
||||||
CoreModule,
|
CoreModule,
|
||||||
SocialModule,
|
|
||||||
TagModule,
|
TagModule,
|
||||||
CommonModule,
|
CommonModule,
|
||||||
WebScriptModule,
|
WebScriptModule,
|
||||||
@ -95,7 +93,6 @@ import { ContentAuthLoaderService } from './auth-loader/content-auth-loader.serv
|
|||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
ContentPipeModule,
|
ContentPipeModule,
|
||||||
SocialModule,
|
|
||||||
TagModule,
|
TagModule,
|
||||||
WebScriptModule,
|
WebScriptModule,
|
||||||
DocumentListModule,
|
DocumentListModule,
|
||||||
|
@ -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';
|
|
@ -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>
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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');
|
|
||||||
});
|
|
||||||
});
|
|
@ -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({});
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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}
|
|
||||||
}
|
|
||||||
};
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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';
|
|
@ -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>
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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();
|
|
||||||
});
|
|
||||||
});
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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>;
|
|
||||||
}
|
|
@ -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
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
@ -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 {}
|
|
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './lib/directives/index';
|
export * from './lib/directives/index';
|
||||||
export * from './lib/social/index';
|
|
||||||
export * from './lib/tag/index';
|
export * from './lib/tag/index';
|
||||||
export * from './lib/webscript/index';
|
export * from './lib/webscript/index';
|
||||||
export * from './lib/document-list/index';
|
export * from './lib/document-list/index';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user