mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
[ACA-213] Edit Offline (#909)
* WRITE_LOCK evaluator * evaluate actions for WRITE_LOCK * edit offline action * DL icon for WRITE_LOCK files * edit offline directive * custom name column * localisation * toggle offline edit extension * move takeUntil operator * add tooltip * better selector to differentiate Edit folder from Edit Offline * default to empty object for null properties object * isPersonalFiles evaluator * isLibraryFiles evaluator * isLibraryFiles evaluator * isPersonalFiles evaluator * update canEditLockedFile rule
This commit is contained in:
committed by
Denys Vuika
parent
5eaa5c1bc7
commit
e004d365a9
@@ -0,0 +1,39 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CustomNameColumnComponent } from './name-column/name-column.component';
|
||||
import { LockByComponent } from './locked-by/locked-by.component';
|
||||
import { ContentModule } from '@alfresco/adf-content-services';
|
||||
import { MaterialModule } from '../../material.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [BrowserModule, ContentModule, MaterialModule],
|
||||
declarations: [CustomNameColumnComponent, LockByComponent],
|
||||
exports: [CustomNameColumnComponent, LockByComponent],
|
||||
entryComponents: [CustomNameColumnComponent, LockByComponent]
|
||||
})
|
||||
export class DocumentListCustomComponentsModule {}
|
@@ -0,0 +1,11 @@
|
||||
.aca-locked-by {
|
||||
.locked_by--icon {
|
||||
font-size: 16px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
.locked_by--name {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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,
|
||||
Input,
|
||||
OnInit,
|
||||
ChangeDetectionStrategy,
|
||||
ViewEncapsulation
|
||||
} from '@angular/core';
|
||||
|
||||
import { NodeEntry } from '@alfresco/js-api';
|
||||
|
||||
@Component({
|
||||
selector: 'aca-locked-by',
|
||||
template: `
|
||||
<mat-icon class="locked_by--icon">lock</mat-icon>
|
||||
<span class="locked_by--name">{{ writeLockedBy() }}</span>
|
||||
`,
|
||||
styleUrls: ['./locked-by.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
host: {
|
||||
class: 'aca-locked-by'
|
||||
}
|
||||
})
|
||||
export class LockByComponent implements OnInit {
|
||||
@Input()
|
||||
context: any;
|
||||
|
||||
node: NodeEntry;
|
||||
|
||||
constructor() {}
|
||||
|
||||
ngOnInit() {
|
||||
this.node = this.context.row.node;
|
||||
}
|
||||
|
||||
writeLockedBy() {
|
||||
return (
|
||||
this.node &&
|
||||
this.node.entry.properties &&
|
||||
this.node.entry.properties['cm:lockOwner'] &&
|
||||
this.node.entry.properties['cm:lockOwner'].displayName
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
.aca-name-column-container {
|
||||
.adf-datatable-cell {
|
||||
top: 8px;
|
||||
}
|
||||
|
||||
aca-locked-by {
|
||||
position: absolute;
|
||||
bottom: 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.aca-custom-name-column {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
@@ -0,0 +1,106 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { CustomNameColumnComponent } from './name-column.component';
|
||||
import { DocumentListCustomComponentsModule } from '../document-list-custom-components.module';
|
||||
import { Actions } from '@ngrx/effects';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
describe('CustomNameColumnComponent', () => {
|
||||
let fixture;
|
||||
let component;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
DocumentListCustomComponentsModule,
|
||||
StoreModule.forRoot({ app: () => {} }, { initialState: {} })
|
||||
],
|
||||
providers: [Actions]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(CustomNameColumnComponent);
|
||||
component = fixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should not render lock element if file is not locked', () => {
|
||||
component.context = {
|
||||
row: {
|
||||
node: {
|
||||
entry: {
|
||||
isFile: true,
|
||||
id: 'nodeId'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(
|
||||
fixture.debugElement.nativeElement.querySelector('aca-locked-by')
|
||||
).toBe(null);
|
||||
});
|
||||
|
||||
it('should not render lock element if node is not a file', () => {
|
||||
component.context = {
|
||||
row: {
|
||||
node: {
|
||||
entry: {
|
||||
isFile: false,
|
||||
id: 'nodeId'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(
|
||||
fixture.debugElement.nativeElement.querySelector('aca-locked-by')
|
||||
).toBe(null);
|
||||
});
|
||||
|
||||
it('should render lock element if file is locked', () => {
|
||||
component.context = {
|
||||
row: {
|
||||
node: {
|
||||
entry: {
|
||||
isFile: true,
|
||||
id: 'nodeId',
|
||||
properties: { 'cm:lockType': 'WRITE_LOCK' }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(
|
||||
fixture.debugElement.nativeElement.querySelector('aca-locked-by')
|
||||
).not.toBe(null);
|
||||
});
|
||||
});
|
@@ -0,0 +1,94 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* 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,
|
||||
Input,
|
||||
OnInit,
|
||||
ViewEncapsulation,
|
||||
ChangeDetectorRef,
|
||||
OnDestroy
|
||||
} from '@angular/core';
|
||||
import { Actions, ofType } from '@ngrx/effects';
|
||||
import { EDIT_OFFLINE } from '../../../store/actions';
|
||||
import { NodeEntry } from '@alfresco/js-api';
|
||||
import { Subject } from 'rxjs';
|
||||
import { filter, takeUntil } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'aca-custom-name-column',
|
||||
template: `
|
||||
<div
|
||||
class="aca-custom-name-column"
|
||||
[ngClass]="{
|
||||
'aca-name-column-container': isFile() && isFileWriteLocked()
|
||||
}"
|
||||
>
|
||||
<adf-name-column [context]="context"></adf-name-column>
|
||||
|
||||
<ng-container *ngIf="isFile() && isFileWriteLocked()">
|
||||
<aca-locked-by [context]="context"></aca-locked-by>
|
||||
</ng-container>
|
||||
</div>
|
||||
`,
|
||||
styleUrls: ['name-column.component.scss'],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class CustomNameColumnComponent implements OnInit, OnDestroy {
|
||||
node: NodeEntry;
|
||||
|
||||
@Input()
|
||||
context: any;
|
||||
|
||||
private onDestroy$: Subject<boolean> = new Subject<boolean>();
|
||||
|
||||
constructor(private cd: ChangeDetectorRef, private actions$: Actions) {}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.onDestroy$.next(true);
|
||||
this.onDestroy$.complete();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.node = this.context.row.node;
|
||||
|
||||
this.actions$
|
||||
.pipe(
|
||||
ofType<any>(EDIT_OFFLINE),
|
||||
filter(val => {
|
||||
return this.node.entry.id === val.payload.entry.id;
|
||||
}),
|
||||
takeUntil(this.onDestroy$)
|
||||
)
|
||||
.subscribe(() => {
|
||||
this.cd.detectChanges();
|
||||
});
|
||||
}
|
||||
|
||||
isFile() {
|
||||
return this.node && this.node.entry && this.node.entry.isFile;
|
||||
}
|
||||
|
||||
isFileWriteLocked() {
|
||||
return !!(
|
||||
this.node &&
|
||||
this.node.entry &&
|
||||
this.node.entry.properties &&
|
||||
this.node.entry.properties['cm:lockType'] === 'WRITE_LOCK'
|
||||
);
|
||||
}
|
||||
}
|
@@ -71,6 +71,10 @@ export abstract class PageComponent implements OnInit, OnDestroy {
|
||||
);
|
||||
}
|
||||
|
||||
static isWriteLockedNode(node) {
|
||||
return node.properties && node.properties['cm:lockType'] === 'WRITE_LOCK';
|
||||
}
|
||||
|
||||
static isLibrary(entry) {
|
||||
return (
|
||||
(entry.guid &&
|
||||
@@ -135,7 +139,10 @@ export abstract class PageComponent implements OnInit, OnDestroy {
|
||||
imageResolver(row: ShareDataRow): string | null {
|
||||
const entry: MinimalNodeEntryEntity = row.node.entry;
|
||||
|
||||
if (PageComponent.isLockedNode(entry)) {
|
||||
if (
|
||||
PageComponent.isLockedNode(entry) ||
|
||||
PageComponent.isWriteLockedNode(entry)
|
||||
) {
|
||||
return 'assets/images/ic_lock_black_24dp_1x.png';
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,132 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { ToggleEditOfflineComponent } from './toggle-edit-offline.component';
|
||||
import { EditOfflineDirective } from '../../../directives/edit-offline.directive';
|
||||
import { setupTestBed, CoreModule } from '@alfresco/adf-core';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { Store } from '@ngrx/store';
|
||||
import {
|
||||
DownloadNodesAction,
|
||||
EditOfflineAction,
|
||||
SnackbarErrorAction
|
||||
} from '../../../store/actions';
|
||||
|
||||
describe('ToggleEditOfflineComponent', () => {
|
||||
let fixture;
|
||||
let component;
|
||||
let selection;
|
||||
let store;
|
||||
let dispatchSpy;
|
||||
|
||||
setupTestBed({
|
||||
imports: [CoreModule],
|
||||
declarations: [ToggleEditOfflineComponent, EditOfflineDirective],
|
||||
providers: [
|
||||
{
|
||||
provide: Store,
|
||||
useValue: {
|
||||
select: () => of(selection),
|
||||
dispatch: () => {}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ToggleEditOfflineComponent);
|
||||
component = fixture.componentInstance;
|
||||
store = TestBed.get(Store);
|
||||
|
||||
dispatchSpy = spyOn(store, 'dispatch');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
dispatchSpy.calls.reset();
|
||||
});
|
||||
|
||||
it('should initialized with data from store', () => {
|
||||
selection = { file: { entry: { properties: {} } } };
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.selection).toEqual(selection.file);
|
||||
});
|
||||
|
||||
it('should download content if node is locked', () => {
|
||||
component.selection = { entry: { properties: {} } };
|
||||
|
||||
const isLocked = true;
|
||||
component.onToggleEvent(isLocked);
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(dispatchSpy.calls.argsFor(0)).toEqual([
|
||||
new DownloadNodesAction([component.selection])
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not download content if node is not locked', () => {
|
||||
component.selection = { entry: { properties: {} } };
|
||||
|
||||
const isLocked = false;
|
||||
component.onToggleEvent(isLocked);
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(dispatchSpy.calls.argsFor(0)).not.toEqual([
|
||||
new DownloadNodesAction([component.selection])
|
||||
]);
|
||||
});
|
||||
|
||||
it('should dispatch EditOfflineAction action', () => {
|
||||
component.selection = { entry: { properties: {} } };
|
||||
|
||||
const isLocked = false;
|
||||
component.onToggleEvent(isLocked);
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(dispatchSpy.calls.argsFor(0)).toEqual([
|
||||
new EditOfflineAction(component.selection)
|
||||
]);
|
||||
});
|
||||
|
||||
it('should raise notification on error', () => {
|
||||
component.selection = {
|
||||
entry: { name: 'test' }
|
||||
};
|
||||
|
||||
component.onError();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(dispatchSpy.calls.argsFor(0)).toEqual([
|
||||
new SnackbarErrorAction('APP.MESSAGES.ERRORS.LOCK_NODE', {
|
||||
fileName: 'test'
|
||||
})
|
||||
]);
|
||||
});
|
||||
});
|
@@ -0,0 +1,91 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AppStore } from '../../../store/states';
|
||||
import { appSelection } from '../../../store/selectors/app.selectors';
|
||||
import {
|
||||
DownloadNodesAction,
|
||||
EditOfflineAction,
|
||||
SnackbarErrorAction
|
||||
} from '../../../store/actions';
|
||||
import { MinimalNodeEntity } from '@alfresco/js-api';
|
||||
|
||||
@Component({
|
||||
selector: 'app-toggle-edit-offline',
|
||||
template: `
|
||||
<button
|
||||
#editOffline="editOffline"
|
||||
mat-menu-item
|
||||
(toggle)="onToggleEvent($event)"
|
||||
(error)="onError()"
|
||||
[acaEditOffline]="selection"
|
||||
[attr.title]="
|
||||
editOffline.isNodeLocked()
|
||||
? ('APP.ACTIONS.EDIT_OFFLINE_CANCEL' | translate)
|
||||
: ('APP.ACTIONS.EDIT_OFFLINE' | translate)
|
||||
"
|
||||
>
|
||||
<ng-container *ngIf="editOffline.isNodeLocked()">
|
||||
<mat-icon>cancel</mat-icon>
|
||||
<span>{{ 'APP.ACTIONS.EDIT_OFFLINE_CANCEL' | translate }}</span>
|
||||
</ng-container>
|
||||
|
||||
<ng-container *ngIf="!editOffline.isNodeLocked()">
|
||||
<mat-icon>edit</mat-icon>
|
||||
<span>{{ 'APP.ACTIONS.EDIT_OFFLINE' | translate }}</span>
|
||||
</ng-container>
|
||||
</button>
|
||||
`,
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
host: { class: 'app-toggle-edit-offline' }
|
||||
})
|
||||
export class ToggleEditOfflineComponent implements OnInit {
|
||||
selection: MinimalNodeEntity;
|
||||
|
||||
constructor(private store: Store<AppStore>) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.store.select(appSelection).subscribe(({ file }) => {
|
||||
this.selection = file;
|
||||
});
|
||||
}
|
||||
|
||||
onToggleEvent(isNodeLocked: boolean) {
|
||||
if (isNodeLocked) {
|
||||
this.store.dispatch(new DownloadNodesAction([this.selection]));
|
||||
}
|
||||
this.store.dispatch(new EditOfflineAction(this.selection));
|
||||
}
|
||||
|
||||
onError() {
|
||||
this.store.dispatch(
|
||||
new SnackbarErrorAction('APP.MESSAGES.ERRORS.LOCK_NODE', {
|
||||
fileName: this.selection.entry.name
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
@@ -38,6 +38,7 @@ import { ToggleJoinLibraryButtonComponent } from './toggle-join-library/toggle-j
|
||||
import { ToggleJoinLibraryMenuComponent } from './toggle-join-library/toggle-join-library-menu.component';
|
||||
import { DirectivesModule } from '../../directives/directives.module';
|
||||
import { ToggleFavoriteLibraryComponent } from './toggle-favorite-library/toggle-favorite-library.component';
|
||||
import { ToggleEditOfflineComponent } from './toggle-edit-offline/toggle-edit-offline.component';
|
||||
import { AppCommonModule } from '../common/common.module';
|
||||
|
||||
export function components() {
|
||||
@@ -51,7 +52,8 @@ export function components() {
|
||||
ToolbarMenuComponent,
|
||||
ToggleJoinLibraryButtonComponent,
|
||||
ToggleJoinLibraryMenuComponent,
|
||||
ToggleFavoriteLibraryComponent
|
||||
ToggleFavoriteLibraryComponent,
|
||||
ToggleEditOfflineComponent
|
||||
];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user