Skip to content

Commit

Permalink
fix: Add config for models to transform ionic date format (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
EndyKaufman committed Mar 10, 2019
1 parent d9efab3 commit afc5fd7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
6 changes: 3 additions & 3 deletions apps/demo/src/app/app.module.ts
Expand Up @@ -9,8 +9,8 @@ import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { IonicStorageModule } from '@ionic/storage';
import { MetaLoader, MetaModule } from '@ngx-meta/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { AccountModule, AuthModalModule, AuthModule, BrowserStorage, CONTENT_TYPES_CONFIG_TOKEN, DEFAULT_CONTENT_TYPES_CONFIG, ErrorsExtractor, GROUPS_CONFIG_TOKEN, LangModule, LangService, PermissionsGuard, PERMISSIONS_CONFIG_TOKEN, PipesModule, STORAGE_CONFIG_TOKEN, TokenService, TransferHttpCacheModule, USERS_CONFIG_TOKEN, DEFAULT_PERMISSIONS_CONFIG, DEFAULT_USERS_CONFIG, DEFAULT_GROUPS_CONFIG } from '@rucken/core';
import { GroupsListFiltersModalModule, GroupsListFiltersModalService, IonicAuthModalModule, IonicModalsModule, NavbarModule, UsersListFiltersModalModule, UsersListFiltersModalService } from '@rucken/ionic';
import { AccountModule, AuthModalModule, AuthModule, BrowserStorage, CONTENT_TYPES_CONFIG_TOKEN, DEFAULT_CONTENT_TYPES_CONFIG, DEFAULT_GROUPS_CONFIG, DEFAULT_PERMISSIONS_CONFIG, ErrorsExtractor, GROUPS_CONFIG_TOKEN, LangModule, LangService, PermissionsGuard, PERMISSIONS_CONFIG_TOKEN, PipesModule, STORAGE_CONFIG_TOKEN, TokenService, TransferHttpCacheModule, USERS_CONFIG_TOKEN } from '@rucken/core';
import { GroupsListFiltersModalModule, GroupsListFiltersModalService, IonicAuthModalModule, IonicModalsModule, IONIC_DEFAULT_USERS_CONFIG, NavbarModule, UsersListFiltersModalModule, UsersListFiltersModalService } from '@rucken/ionic';
import { NgxBindIOModule } from 'ngx-bind-io';
import { CookieService } from 'ngx-cookie-service';
import { NgxPermissionsModule } from 'ngx-permissions';
Expand Down Expand Up @@ -86,7 +86,7 @@ import { metaFactory } from './utils/meta-factory';
{
provide: USERS_CONFIG_TOKEN,
useValue: {
...DEFAULT_USERS_CONFIG,
...IONIC_DEFAULT_USERS_CONFIG,
apiUrl: environment.apiUrl
}
},
Expand Down
Expand Up @@ -23,7 +23,8 @@
<ion-fab
vertical="bottom"
horizontal="end"
slot="fixed">
slot="fixed"
*ngIf="groupList?.list?.notReadonlyAndEnableCreate$|async">
<ion-fab-button (click)="groupList.onCreateClick()">
<ion-icon name="add"></ion-icon>
</ion-fab-button>
Expand Down
3 changes: 2 additions & 1 deletion apps/demo/src/app/pages/users-page/users-page.component.html
Expand Up @@ -23,7 +23,8 @@
<ion-fab
vertical="bottom"
horizontal="end"
slot="fixed">
slot="fixed"
*ngIf="userList?.list?.notReadonlyAndEnableCreate$|async">
<ion-fab-button (click)="userList.onCreateClick()">
<ion-icon name="add"></ion-icon>
</ion-fab-button>
Expand Down
33 changes: 33 additions & 0 deletions libs/rucken/ionic/src/lib/config/users.config.ts
@@ -0,0 +1,33 @@
import { plainToClass } from 'class-transformer';
import { IRestProviderOptions, PaginationMeta, ProviderActionEnum } from 'ngx-repository';
import { CustomUser } from '../models/custom-user';

export const IONIC_DEFAULT_USERS_CONFIG: IRestProviderOptions<CustomUser> = {
name: 'user',
pluralName: 'users',
autoload: true,
paginationMeta: {
perPage: 5
},
actionOptions: {
responseData: (data: any, action: ProviderActionEnum) => {
if (action === ProviderActionEnum.Delete) {
return true;
} else {
if (action === ProviderActionEnum.LoadAll) {
return plainToClass(CustomUser, data && data.body && data.body.users);
} else {
return plainToClass(CustomUser, data && data.body && data.body.user);
}
}
},
responsePaginationMeta: (data: any, action: ProviderActionEnum): PaginationMeta => {
return { totalResults: data && data.body && data.body.meta && data.body.meta.totalResults, perPage: undefined };
}
},
restOptions: {
limitQueryParam: 'per_page',
pageQueryParam: 'cur_page',
searchTextQueryParam: 'q'
}
};
6 changes: 3 additions & 3 deletions libs/rucken/ionic/src/lib/models/custom-user.ts
@@ -1,8 +1,8 @@
import { User, transformDateToString } from '@rucken/core';
import { transformDateToString, transformStringToDate, User } from '@rucken/core';
import { Transform } from 'class-transformer';

export class CustomUser extends User {
@Transform(transformDateToString, { toClassOnly: true })
@Transform(transformDateToString, { toPlainOnly: true })
dateOfBirth: Date = undefined;
@Transform(transformStringToDate, { toPlainOnly: true })
dateOfBirth: Date | string = undefined;
}

0 comments on commit afc5fd7

Please sign in to comment.