[ACA-1443] prettier formatting and checks (#629)

* intergrate prettier

* update settings

* integrate with travis

* unified formatting across all files
This commit is contained in:
Denys Vuika
2018-09-13 16:47:55 +01:00
committed by GitHub
parent 06402a9c72
commit 883a1971c5
163 changed files with 13571 additions and 12512 deletions

View File

@@ -1,16 +1,16 @@
:host {
display: flex;
flex: 1;
display: flex;
flex: 1;
}
@media screen and (max-width: 599px) {
.adf-app-title {
display: none;
}
.adf-app-title {
display: none;
}
}
@media screen and (max-width: 719px) {
.adf-app-logo {
display: none;
}
.adf-app-logo {
display: none;
}
}

View File

@@ -31,85 +31,82 @@ import { SidenavViewsManagerDirective } from './sidenav-views-manager.directive'
import { AppTestingModule } from '../../testing/app-testing.module';
describe('LayoutComponent', () => {
let fixture: ComponentFixture<LayoutComponent>;
let component: LayoutComponent;
let appConfig: AppConfigService;
let userPreference: UserPreferencesService;
let fixture: ComponentFixture<LayoutComponent>;
let component: LayoutComponent;
let appConfig: AppConfigService;
let userPreference: UserPreferencesService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ AppTestingModule ],
declarations: [
LayoutComponent,
SidenavViewsManagerDirective
],
schemas: [ NO_ERRORS_SCHEMA ]
});
fixture = TestBed.createComponent(LayoutComponent);
component = fixture.componentInstance;
appConfig = TestBed.get(AppConfigService);
userPreference = TestBed.get(UserPreferencesService);
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [LayoutComponent, SidenavViewsManagerDirective],
schemas: [NO_ERRORS_SCHEMA]
});
describe('sidenav state', () => {
it('should get state from configuration', () => {
appConfig.config = {
sideNav: {
expandedSidenav: false,
preserveState: false
}
};
fixture = TestBed.createComponent(LayoutComponent);
component = fixture.componentInstance;
appConfig = TestBed.get(AppConfigService);
userPreference = TestBed.get(UserPreferencesService);
});
fixture.detectChanges();
describe('sidenav state', () => {
it('should get state from configuration', () => {
appConfig.config = {
sideNav: {
expandedSidenav: false,
preserveState: false
}
};
expect(component.expandedSidenav).toBe(false);
});
fixture.detectChanges();
it('should resolve state to true is no configuration', () => {
appConfig.config = {};
fixture.detectChanges();
expect(component.expandedSidenav).toBe(true);
});
it('should get state from user settings as true', () => {
appConfig.config = {
sideNav: {
expandedSidenav: false,
preserveState: true
}
};
spyOn(userPreference, 'get').and.callFake(key => {
if (key === 'expandedSidenav') {
return 'true';
}
});
fixture.detectChanges();
expect(component.expandedSidenav).toBe(true);
});
it('should get state from user settings as false', () => {
appConfig.config = {
sideNav: {
expandedSidenav: false,
preserveState: true
}
};
spyOn(userPreference, 'get').and.callFake(key => {
if (key === 'expandedSidenav') {
return 'false';
}
});
fixture.detectChanges();
expect(component.expandedSidenav).toBe(false);
});
expect(component.expandedSidenav).toBe(false);
});
});
it('should resolve state to true is no configuration', () => {
appConfig.config = {};
fixture.detectChanges();
expect(component.expandedSidenav).toBe(true);
});
it('should get state from user settings as true', () => {
appConfig.config = {
sideNav: {
expandedSidenav: false,
preserveState: true
}
};
spyOn(userPreference, 'get').and.callFake(key => {
if (key === 'expandedSidenav') {
return 'true';
}
});
fixture.detectChanges();
expect(component.expandedSidenav).toBe(true);
});
it('should get state from user settings as false', () => {
appConfig.config = {
sideNav: {
expandedSidenav: false,
preserveState: true
}
};
spyOn(userPreference, 'get').and.callFake(key => {
if (key === 'expandedSidenav') {
return 'false';
}
});
fixture.detectChanges();
expect(component.expandedSidenav).toBe(false);
});
});
});

View File

@@ -24,11 +24,11 @@
*/
import {
Component,
OnInit,
OnDestroy,
ViewChild,
ViewEncapsulation
Component,
OnInit,
OnDestroy,
ViewChild,
ViewEncapsulation
} from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
@@ -37,76 +37,72 @@ import { SidenavViewsManagerDirective } from './sidenav-views-manager.directive'
import { Store } from '@ngrx/store';
import { AppStore } from '../../store/states';
import {
currentFolder,
selectAppName,
selectHeaderColor,
selectLogoPath
currentFolder,
selectAppName,
selectHeaderColor,
selectLogoPath
} from '../../store/selectors/app.selectors';
import { takeUntil } from 'rxjs/operators';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
@Component({
selector: 'app-layout',
templateUrl: './layout.component.html',
styleUrls: ['./layout.component.scss'],
encapsulation: ViewEncapsulation.None,
host: { class: 'app-layout' }
selector: 'app-layout',
templateUrl: './layout.component.html',
styleUrls: ['./layout.component.scss'],
encapsulation: ViewEncapsulation.None,
host: { class: 'app-layout' }
})
export class LayoutComponent implements OnInit, OnDestroy {
@ViewChild(SidenavViewsManagerDirective)
manager: SidenavViewsManagerDirective;
@ViewChild(SidenavViewsManagerDirective)
manager: SidenavViewsManagerDirective;
onDestroy$: Subject<boolean> = new Subject<boolean>();
expandedSidenav: boolean;
node: MinimalNodeEntryEntity;
canUpload = false;
onDestroy$: Subject<boolean> = new Subject<boolean>();
expandedSidenav: boolean;
node: MinimalNodeEntryEntity;
canUpload = false;
appName$: Observable<string>;
headerColor$: Observable<string>;
logo$: Observable<string>;
appName$: Observable<string>;
headerColor$: Observable<string>;
logo$: Observable<string>;
isSmallScreen = false;
isSmallScreen = false;
constructor(
protected store: Store<AppStore>,
private permission: NodePermissionService,
private breakpointObserver: BreakpointObserver
) {
this.headerColor$ = store.select(selectHeaderColor);
this.appName$ = store.select(selectAppName);
this.logo$ = store.select(selectLogoPath);
constructor(
protected store: Store<AppStore>,
private permission: NodePermissionService,
private breakpointObserver: BreakpointObserver
) {
this.headerColor$ = store.select(selectHeaderColor);
this.appName$ = store.select(selectAppName);
this.logo$ = store.select(selectLogoPath);
}
ngOnInit() {
if (!this.manager.minimizeSidenav) {
this.expandedSidenav = this.manager.sidenavState;
} else {
this.expandedSidenav = false;
}
ngOnInit() {
if (!this.manager.minimizeSidenav) {
this.expandedSidenav = this.manager.sidenavState;
} else {
this.expandedSidenav = false;
}
this.manager.run(true);
this.manager.run(true);
this.store
.select(currentFolder)
.pipe(takeUntil(this.onDestroy$))
.subscribe(node => {
this.node = node;
this.canUpload = node && this.permission.check(node, ['create']);
});
this.store
.select(currentFolder)
.pipe(takeUntil(this.onDestroy$))
.subscribe(node => {
this.node = node;
this.canUpload =
node && this.permission.check(node, ['create']);
});
this.breakpointObserver
.observe([Breakpoints.HandsetPortrait, Breakpoints.HandsetLandscape])
.subscribe(result => {
this.isSmallScreen = result.matches;
});
}
this.breakpointObserver
.observe([
Breakpoints.HandsetPortrait,
Breakpoints.HandsetLandscape
])
.subscribe(result => {
this.isSmallScreen = result.matches;
});
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
}

View File

@@ -1,93 +1,92 @@
import { Directive, ContentChild } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import {
UserPreferencesService,
AppConfigService,
SidenavLayoutComponent
UserPreferencesService,
AppConfigService,
SidenavLayoutComponent
} from '@alfresco/adf-core';
import { filter } from 'rxjs/operators';
@Directive({
selector: '[acaSidenavManager]',
exportAs: 'acaSidenavManager'
selector: '[acaSidenavManager]',
exportAs: 'acaSidenavManager'
})
export class SidenavViewsManagerDirective {
@ContentChild(SidenavLayoutComponent) sidenavLayout: SidenavLayoutComponent;
@ContentChild(SidenavLayoutComponent)
sidenavLayout: SidenavLayoutComponent;
minimizeSidenav = false;
hideSidenav = false;
minimizeSidenav = false;
hideSidenav = false;
private _run = false;
private minimizeConditions: string[] = ['search'];
private hideConditions: string[] = ['preview'];
private _run = false;
private minimizeConditions: string[] = ['search'];
private hideConditions: string[] = ['preview'];
constructor(
private router: Router,
private userPreferenceService: UserPreferencesService,
private appConfigService: AppConfigService
constructor(
private router: Router,
private userPreferenceService: UserPreferencesService,
private appConfigService: AppConfigService
) {
this.router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe((event: any) => {
this.minimizeSidenav = this.minimizeConditions.some(el =>
event.urlAfterRedirects.includes(el)
);
this.hideSidenav = this.hideConditions.some(el =>
event.urlAfterRedirects.includes(el)
);
if (this._run) {
this.manageSidenavState();
}
});
}
run(shouldRun) {
this._run = shouldRun;
}
manageSidenavState() {
if (this.minimizeSidenav && !this.sidenavLayout.isMenuMinimized) {
this.sidenavLayout.isMenuMinimized = true;
this.sidenavLayout.container.toggleMenu();
}
if (!this.minimizeSidenav) {
if (this.sidenavState && this.sidenavLayout.isMenuMinimized) {
this.sidenavLayout.isMenuMinimized = false;
this.sidenavLayout.container.toggleMenu();
}
}
}
setState(state) {
if (
!this.minimizeSidenav &&
this.appConfigService.get('sideNav.preserveState')
) {
this.router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe((event: any) => {
this.minimizeSidenav = this.minimizeConditions.some(el =>
event.urlAfterRedirects.includes(el)
);
this.hideSidenav = this.hideConditions.some(el =>
event.urlAfterRedirects.includes(el)
);
this.userPreferenceService.set('expandedSidenav', state);
}
}
if (this._run) {
this.manageSidenavState();
}
});
get sidenavState(): boolean {
const expand = this.appConfigService.get<boolean>(
'sideNav.expandedSidenav',
true
);
const preserveState = this.appConfigService.get<boolean>(
'sideNav.preserveState',
true
);
if (preserveState) {
return (
this.userPreferenceService.get('expandedSidenav', expand.toString()) ===
'true'
);
}
run(shouldRun) {
this._run = shouldRun;
}
manageSidenavState() {
if (this.minimizeSidenav && !this.sidenavLayout.isMenuMinimized) {
this.sidenavLayout.isMenuMinimized = true;
this.sidenavLayout.container.toggleMenu();
}
if (!this.minimizeSidenav) {
if (this.sidenavState && this.sidenavLayout.isMenuMinimized) {
this.sidenavLayout.isMenuMinimized = false;
this.sidenavLayout.container.toggleMenu();
}
}
}
setState(state) {
if (
!this.minimizeSidenav &&
this.appConfigService.get('sideNav.preserveState')
) {
this.userPreferenceService.set('expandedSidenav', state);
}
}
get sidenavState(): boolean {
const expand = this.appConfigService.get<boolean>(
'sideNav.expandedSidenav',
true
);
const preserveState = this.appConfigService.get<boolean>(
'sideNav.preserveState',
true
);
if (preserveState) {
return (
this.userPreferenceService.get(
'expandedSidenav',
expand.toString()
) === 'true'
);
}
return expand;
}
return expand;
}
}