Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
feat(base-resources-grid): Move base methods and props to base-resour…
Browse files Browse the repository at this point in the history
…ces-list from base-resources-grid and base-resources-select-input
  • Loading branch information
EndyKaufman committed Nov 9, 2017
1 parent 73179ba commit 60ad68f
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 189 deletions.
60 changes: 30 additions & 30 deletions apps/demo/src/app/i18n/ru.i18n.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
export const RuckenDemoRuI18n = {
'': {
'project-id-version': '',
'pot-creation-date': '',
'po-revision-date': '',
'last-translator': '',
'language-team': '',
'language': 'ru',
'mime-version': '1.0',
'content-type': 'text/plain; charset=UTF-8',
'content-transfer-encoding': '8bit',
'x-generator': 'Poedit 2.0.4',
'plural-forms': 'nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);'
},
'Loading...': 'Загрузка...',
'Russian': 'Русский',
'English': 'Английский',
'Account': 'Личный кабинет',
'Profile': 'Профиль',
'Admin': 'Администрирование',
'Groups': 'Группы',
'Users': 'Пользователи',
'Components': 'Компоненты',
'Controls': 'Контролы',
'Home': 'Домашняя страница',
'Themes': 'Темы',
'Language': 'Язык',
'Menu': 'Меню',
'Rucken: Demo': 'Rucken: Todo',
'Logout': 'Выйти',
'Login': 'Вход'
'': {
'project-id-version': '',
'pot-creation-date': '',
'po-revision-date': '',
'last-translator': '',
'language-team': '',
'language': 'ru',
'mime-version': '1.0',
'content-type': 'text/plain; charset=UTF-8',
'content-transfer-encoding': '8bit',
'x-generator': 'Poedit 2.0.4',
'plural-forms': 'nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);'
},
'Loading...': 'Загрузка...',
'Russian': 'Русский',
'English': 'Английский',
'Account': 'Личный кабинет',
'Profile': 'Профиль',
'Admin': 'Администрирование',
'Groups': 'Группы',
'Users': 'Пользователи',
'Components': 'Компоненты',
'Controls': 'Контролы',
'Home': 'Домашняя страница',
'Themes': 'Темы',
'Language': 'Язык',
'Menu': 'Меню',
'Rucken: Demo': 'Rucken: Todo',
'Logout': 'Выйти',
'Login': 'Вход'
};
4 changes: 2 additions & 2 deletions apps/demo/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import { DemoAccountPageModule } from './pages/account-page/account-page.module'
export { DemoAccountPageModule } from './pages/account-page/account-page.module';
import { DemoAccountPageRoutes } from './pages/account-page/account-page.routes';
export { DemoAccountPageRoutes } from './pages/account-page/account-page.routes';
import { DemoProfileFrameModule } from './pages/account-page/profile-frame/profile-frame.module';
export { DemoProfileFrameModule } from './pages/account-page/profile-frame/profile-frame.module';
import { DemoProfileFrameRoutes } from './pages/account-page/profile-frame/profile-frame.routes';
export { DemoProfileFrameRoutes } from './pages/account-page/profile-frame/profile-frame.routes';
import { DemoProfileFrameModule } from './pages/account-page/profile-frame/profile-frame.module';
export { DemoProfileFrameModule } from './pages/account-page/profile-frame/profile-frame.module';
import { DemoAdminPageModule } from './pages/admin-page/admin-page.module';
export { DemoAdminPageModule } from './pages/admin-page/admin-page.module';
import { DemoAdminPageRoutes } from './pages/admin-page/admin-page.routes';
Expand Down
10 changes: 5 additions & 5 deletions libs/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ import { UserGroupsService } from './shared/services/user-groups.service';
export { UserGroupsService } from './shared/services/user-groups.service';
import { UsersService } from './shared/services/users.service';
export { UsersService } from './shared/services/users.service';
import { BaseRemoteRepositoryService } from './shared/base/services/base-remote-repository.service';
export { BaseRemoteRepositoryService } from './shared/base/services/base-remote-repository.service';
import { BaseResourceModel } from './shared/base/models/base-resource.model';
export { BaseResourceModel } from './shared/base/models/base-resource.model';
import { BaseLocalRepositoryService } from './shared/base/services/base-local-repository.service';
export { BaseLocalRepositoryService } from './shared/base/services/base-local-repository.service';
import { BaseRemoteRepositoryService } from './shared/base/services/base-remote-repository.service';
export { BaseRemoteRepositoryService } from './shared/base/services/base-remote-repository.service';
import { BaseRepositoryService } from './shared/base/services/base-repository.service';
export { BaseRepositoryService } from './shared/base/services/base-repository.service';
import { BaseResourceModel } from './shared/base/models/base-resource.model';
export { BaseResourceModel } from './shared/base/models/base-resource.model';
export const RuckenCoreModules: any[] = [];
export const RuckenCoreComponents: any[] = [];
export const RuckenCoreShareds: any[] = [RuckenCoreRuI18n, translate, isJson, inValues, EndpointStatusEnum, EndpointHelper, HttpHelper, RepositoryHelper, FontawesomeItemsMock, ThemeItemsMock, ContentType, Fontawesome, GroupPermission, Group, MetaModel, Permission, Theme, UserGroup, User, BaseResourceModel];
export const RuckenCoreServices: any[] = [AccountService, AppService, ContentTypesService, FontawesomeService, GroupPermissionsService, GroupsService, PermissionsService, ThemesService, UserGroupsService, UsersService, BaseRemoteRepositoryService, BaseLocalRepositoryService, BaseRepositoryService];
export const RuckenCoreServices: any[] = [AccountService, AppService, ContentTypesService, FontawesomeService, GroupPermissionsService, GroupsService, PermissionsService, ThemesService, UserGroupsService, UsersService, BaseLocalRepositoryService, BaseRemoteRepositoryService, BaseRepositoryService];
export const RuckenCorePipes: any[] = [];
2 changes: 1 addition & 1 deletion libs/core/src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/core/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"lodash": "*",
"moment": "*"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { EndpointStatusEnum } from '@rucken/core';

import { BaseComponent } from './../../../base/base-component/base-component.component';
import { BaseResourceSelectInputConfig } from './base-resource-select-input.config';
import { BaseResourcesListComponent } from '../base-resources-list/base-resources-list.component';

@Component({
selector: 'base-resource-select-input',
template: ''
})
export class BaseResourceSelectInputComponent extends BaseComponent {
export class BaseResourceSelectInputComponent extends BaseResourcesListComponent {

@Input()
labelClass?= 'control-label';
Expand Down Expand Up @@ -47,11 +48,6 @@ export class BaseResourceSelectInputComponent extends BaseComponent {
select?: boolean;
@Input()
width: string = null;
@Input()
loadAll?: boolean;

items: any[];
cachedResourcesService: any;

config: BaseResourceSelectInputConfig;

Expand All @@ -73,16 +69,6 @@ export class BaseResourceSelectInputComponent extends BaseComponent {
this.modelAsString = val;
this.modelAsStringChange.emit(this.modelAsString);
}
get statusListMessage() {
if (!this.cachedResourcesService) {
return '';
}
if (this.cachedResourcesService.statusList === EndpointStatusEnum.Ok) {
return '';
} else {
return this.cachedResourcesService.statusListMessage;
}
}

constructor(
public injector: Injector
Expand All @@ -91,10 +77,17 @@ export class BaseResourceSelectInputComponent extends BaseComponent {
this.config = injector.get(BaseResourceSelectInputConfig);
}
afterCreate() {
super.afterCreate();
if (this.select === undefined) {
this.select = this.config.select;
}
if (this.loadAll === undefined) {
if (this.select) {
this.loadAll = true;
} else {
this.loadAll = false;
}
}
super.afterCreate();
if (this.lookupIcon === undefined) {
this.lookupIcon = this.config.lookupIcon;
}
Expand All @@ -110,33 +103,17 @@ export class BaseResourceSelectInputComponent extends BaseComponent {
if (this.inputReadonly === undefined) {
this.inputReadonly = true;
}
if (this.loadAll === undefined) {
if (this.select) {
this.loadAll = true;
} else {
this.loadAll = false;
}
}
if (this.inputElement) {
this.inputElement.hardValue = this.hardValue;
}
this.translateService.onLangChange.takeUntil(this.destroyed$).subscribe(() => this.initSearch());
if (this.cachedResourcesService) {
this.cachedResourcesService.items$.takeUntil(this.destroyed$).subscribe(
(pageTypes: any[]) => {
this.items = pageTypes;
if (this.inputElement) {
this.inputElement.items = this.items;
this.inputElement.init();
}
}, (errors: any) => {
this.items = [];
});
}
}
init() {
super.init();
this.initSearch();
this.onLoaded.subscribe((items: any[]) => {
this.items = items;
if (this.inputElement) {
this.inputElement.items = this.items;
this.inputElement.init();
}
});
}
initSearch() {
if (this.lookupTooltip === undefined) {
Expand All @@ -146,10 +123,4 @@ export class BaseResourceSelectInputComponent extends BaseComponent {
this.search();
}
}
search() {
const filter: any = {};
if (this.cachedResourcesService) {
this.cachedResourcesService.loadAll('', filter);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import { EndpointStatusEnum, User } from '@rucken/core';
import * as _ from 'lodash';

import { BaseComponent } from './../../base/base-component/base-component.component';
import { BaseResourcesListComponent } from './base-resources-list/base-resources-list.component';

@Component({
selector: 'base-resources-grid',
template: ''
})
export class BaseResourcesGridComponent extends BaseComponent {
export class BaseResourcesGridComponent extends BaseResourcesListComponent {

@Input()
loadAll?: boolean;
@Output()
onSelectItems: EventEmitter<any> = new EventEmitter<any>();
@Input()
Expand All @@ -26,20 +25,10 @@ export class BaseResourcesGridComponent extends BaseComponent {
hardReadonly?: boolean;

modelMeta: any;
items: any[];
mockedItems?: any[];
searchText = '';
selectedItems: any[];
cachedResourcesService: any;
maxSelectCount = 1;
modalIsOpened?: boolean;

accessToRead = false;
accessToAdd = false;
accessToChange = false;
accessToDelete = false;
accessToManage = false;

@HostListener('document:keypress', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
if (event.key === 'Enter' && this.onEnterEnabled) {
Expand All @@ -66,69 +55,25 @@ export class BaseResourcesGridComponent extends BaseComponent {
}
return this.cachedResourcesService.columns;
}
get statusListMessage() {
if (!this.cachedResourcesService) {
return '';
}
if (this.cachedResourcesService.statusList === EndpointStatusEnum.Ok) {
return '';
} else {
return this.cachedResourcesService.statusListMessage;
}
}

enter() {
this.onEnter.emit(true);
}
pageChanged(event: any): void {
if (this.cachedResourcesService) {
this.cachedResourcesService.meta.curPage = event.page;
this.cachedResourcesService.meta.perPage = event.itemsPerPage;
this.search();
}
}
init() {
super.init();
this.initAccesses(this.cachedResourcesService ? this.cachedResourcesService.name : null);
if (this.loadAll) {
this.search();
}
}
initAccesses(contentType?: string) {
contentType = contentType ? contentType : this.cachedResourcesService.name;
this.accessToManage = this.checkPermissions(['manage_' + contentType]);
this.accessToRead = this.accessToManage ? this.accessToManage : this.checkPermissions(['read_' + contentType]);
this.accessToAdd = this.accessToManage ? this.accessToManage : this.checkPermissions(['add_' + contentType]);
this.accessToChange = this.accessToManage ? this.accessToManage : this.checkPermissions(['change_' + contentType]);
this.accessToDelete = this.accessToManage ? this.accessToManage : this.checkPermissions(['delete_' + contentType]);
}
afterCreate() {
super.afterCreate();
if (this.loadAll === undefined) {
this.loadAll = true;
}
if (this.onEnterEnabled === undefined) {
this.onEnterEnabled = true;
}
if (this.hardReadonly === undefined) {
this.hardReadonly = false;
}
if (this.cachedResourcesService) {
this.cachedResourcesService.items$.takeUntil(this.destroyed$).subscribe(
(items: any[]) => {
this.items = items;
if (this.items) {
this.selectItem(this.items[0], undefined, true);
}
}, (errors: any) => {
this.items = [];
this.selectItem(null);
});
this.items = this.cachedResourcesService.items;
}
if (this.accountService) {
this.accountService.account$.takeUntil(this.destroyed$).subscribe((account: any | User) => this.initAccesses());
}
this.onLoaded.subscribe((items: any[]) => {
if (items.length) {
this.selectItem(items[0]);
} else {
this.selectItem(null);
}
});
}
focus() {
this.modalIsOpened = false;
Expand Down Expand Up @@ -157,17 +102,4 @@ export class BaseResourcesGridComponent extends BaseComponent {
isSelectedItem(item: any) {
return this.selectedItems && this.selectedItems.filter(i => i && i.pk === item.pk).length > 0;
}
search(ignoreCache?: boolean) {
const filter: any = {};
if (this.cachedResourcesService) {
this.cachedResourcesService.ignoreCache = ignoreCache;
this.searchWithMockedItems(filter);
}
}
searchWithMockedItems(filter: any) {
if (this.mockedItems) {
this.cachedResourcesService.mockedItems = this.mockedItems;
}
this.cachedResourcesService.loadAll(this.searchText, filter);
}
}
Loading

0 comments on commit 60ad68f

Please # to comment.