Skip to content

Commit

Permalink
Merge pull request #432 from ever-co/feature/EV-1155-merchants-setup-…
Browse files Browse the repository at this point in the history
…admin-app

Feature/ev 1155 merchants setup admin app
  • Loading branch information
evereq committed Apr 12, 2019
2 parents d52fad8 + eb75361 commit 032d300
Show file tree
Hide file tree
Showing 72 changed files with 2,087 additions and 870 deletions.
5 changes: 3 additions & 2 deletions admin/website-angular/package.json
Expand Up @@ -112,6 +112,7 @@
"ionicons": "^4.5.5",
"is-url": "^1.2.4",
"jquery": "^3.3.1",
"jsbarcode": "^3.11.0",
"leaflet": "^1.4.0",
"moment": "^2.24.0",
"nebular-icons": "1.1.0",
Expand Down Expand Up @@ -197,9 +198,9 @@
"ts-node": "^8.0.2",
"tslint": "^5.12.1",
"tslint-language-service": "^0.9.9",
"yargs": "^13.1.0",
"typescript": "~3.1.6",
"webpack-dev-server": "^3.2.1",
"typescript": "~3.1.6"
"yargs": "^13.1.0"
},
"engines": {
"node": ">=10.15.0",
Expand Down
Expand Up @@ -50,6 +50,7 @@ export class ProductsCategoryService {
) {
createProductsCategory(createInput: $productsCategory) {
id
image
name {
locale
value
Expand Down Expand Up @@ -86,6 +87,8 @@ export class ProductsCategoryService {
id: $id
updateInput: $productsCategory
) {
id
image
name {
locale
value
Expand Down
Expand Up @@ -223,14 +223,18 @@

<div class="form-group row">
<!-- TODO add translate -->
<nb-checkbox class="col-sm-12" formControlName="isSharedCarrier"
>Carrier can be shared?</nb-checkbox
<nb-checkbox
class="col-sm-12"
formControlName="isSharedCarrier"
>
<nb-checkbox class="col-sm-12" formControlName="isActive">
{{
'CARRIERS_VIEW.CARRIER_PAGE.ACTIVE' | translate
}}</nb-checkbox
>
'CARRIERS_VIEW.CARRIER_PAGE.CARRIER_CAN_BE_SHARED'
| translate
}}
</nb-checkbox>
<nb-checkbox class="col-sm-12" formControlName="isActive">
{{ 'CARRIERS_VIEW.CARRIER_PAGE.ACTIVE' | translate }}
</nb-checkbox>
</div>
</fieldset>
</div>
Expand Down
Expand Up @@ -16,7 +16,3 @@
font-size: 1.1em;
}
}

.no-box-shadow {
box-shadow: none;
}
@@ -1,4 +1,11 @@
import { Component, OnDestroy } from '@angular/core';
import {
Component,
OnDestroy,
Input,
OnInit,
Output,
EventEmitter
} from '@angular/core';
import { LocalDataSource } from 'ng2-smart-table';
import ProductsCategory from '@modules/server.common/entities/ProductsCategory';
import { ProductsCategoryService } from '../../../../@core/data/productsCategory.service';
Expand Down Expand Up @@ -26,18 +33,30 @@ interface ProductViewModel {
styleUrls: ['./categories-table.component.scss'],
templateUrl: './categories-table.component.html'
})
export class CategoriesTableComponent implements OnDestroy {
private ngDestroy$ = new Subject<void>();
export class CategoriesTableComponent implements OnInit, OnDestroy {
@Input()
selectMode = 'multi';
@Input()
showPerPage = 7;
@Input()
editWithModal = true;

@Output()
editRow = new EventEmitter();
@Output()
deleteRow = new EventEmitter();

productsCategories: ProductsCategory[] = [];
loading: boolean;

public confirmSub$: Subscription;
confirmSub$: Subscription;

settingsSmartTable: object;
sourceSmartTable = new LocalDataSource();

private static noInfoSign = '';
private _selectedCategories: ProductViewModel[] = [];
public productsCategories: ProductsCategory[] = [];
public loading: boolean;
private ngDestroy$ = new Subject<void>();

constructor(
private readonly _translateService: TranslateService,
Expand All @@ -46,10 +65,7 @@ export class CategoriesTableComponent implements OnDestroy {
private readonly _modalService: NgbModal,
private readonly _notifyService: NotifyService,
private readonly modalService: NgbModal
) {
this._loadSettingsSmartTable();
this._applyTranslationOnSmartTable();
}
) {}

get hasSelectedCategories(): boolean {
return this._selectedCategories.length > 0;
Expand All @@ -59,15 +75,23 @@ export class CategoriesTableComponent implements OnDestroy {
return [...this._selectedCategories];
}

ngOnInit(): void {
this._loadSettingsSmartTable();
this._applyTranslationOnSmartTable();
}
edit(ev) {
const activeModal = this._modalService.open(CategoryEditComponent, {
size: 'lg',
container: 'nb-layout',
backdrop: 'static'
});
const modalComponent: CategoryEditComponent =
activeModal.componentInstance;
modalComponent.currentCategory = ev.data;
if (this.editWithModal) {
const activeModal = this._modalService.open(CategoryEditComponent, {
size: 'lg',
container: 'nb-layout',
backdrop: 'static'
});
const modalComponent: CategoryEditComponent =
activeModal.componentInstance;
modalComponent.currentCategory = ev.data;
} else {
this.editRow.emit(ev.data);
}
}

async deleteCategory(e) {
Expand All @@ -87,13 +111,18 @@ export class CategoriesTableComponent implements OnDestroy {

try {
this.loading = true;

this._productsCategoryService
.removeByIds(idsArray)
.pipe()
.toPromise();

this.loading = false;

const message = `Category '${e.data.title}' deleted`;
this._notifyService.success(message);

this.deleteRow.emit(e.data);
} catch (error) {
this.loading = false;
const message = `Something went wrong!`;
Expand Down Expand Up @@ -124,7 +153,7 @@ export class CategoriesTableComponent implements OnDestroy {
this.sourceSmartTable.load(categoriesVM);
}

protected localeTranslate(member: ILocaleMember[]) {
localeTranslate(member: ILocaleMember[]) {
return this._productLocalesService.getTranslate(member);
}

Expand All @@ -144,7 +173,7 @@ export class CategoriesTableComponent implements OnDestroy {
.pipe(takeUntil(this.ngDestroy$))
.subscribe(([image, titleTr]) => {
this.settingsSmartTable = {
selectMode: 'multi',
selectMode: this.selectMode,
mode: 'external',
actions: {
add: false,
Expand All @@ -169,7 +198,7 @@ export class CategoriesTableComponent implements OnDestroy {
},
pager: {
display: true,
perPage: 7
perPage: this.showPerPage
}
};
});
Expand Down
Expand Up @@ -19,7 +19,7 @@
<button
class="btn btn-success"
type="button"
(click)="editCategory(basicInfo.editObject)"
(click)="editCategory(basicInfo.getEditObject(currentCategory))"
[disabled]="basicInfo.form.invalid"
>
{{ 'CATEGORY_VIEW.EDIT.DONE' | translate }}!
Expand Down
@@ -1,15 +1,10 @@
import { Component, OnDestroy } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import 'rxjs/operators/map';
import { Subject } from 'rxjs';
import { first } from 'rxjs/operators';
import { ProductsCategoryService } from '../../../../@core/data/productsCategory.service';
import {
IProductsCategoryCreateObject,
IProductsCategoryName
} from '@modules/server.common/interfaces/IProductsCategory';
import { TranslateService } from '@ngx-translate/core';
import { IProductsCategoryName } from '@modules/server.common/interfaces/IProductsCategory';
import { ProductLocalesService } from '@modules/client.common.angular2/locale/product-locales.service';
import { ILocaleMember } from '@modules/server.common/interfaces/ILocale';
import { NotifyService } from 'app/@core/services/notify/notify.service';
Expand All @@ -34,7 +29,6 @@ export class CategoryEditComponent implements OnDestroy {
constructor(
private readonly _activeModal: NgbActiveModal,
private readonly _productsCategoryService: ProductsCategoryService,
private readonly _langTranslateService: TranslateService,
private readonly _productLocalesService: ProductLocalesService,
private readonly _notifyService: NotifyService
) {}
Expand All @@ -48,30 +42,7 @@ export class CategoryEditComponent implements OnDestroy {
this._activeModal.dismiss('canceled');
}

async editCategory(categoryObject) {
let usedLanguage = this._langTranslateService.currentLang;
switch (usedLanguage) {
case 'en':
usedLanguage += '-US';
break;
case 'bg':
usedLanguage += '-BG';
break;
case 'he':
usedLanguage += '-IL';
break;
case 'ru':
usedLanguage += '-RU';
break;
default:
usedLanguage = 'en-US';
}

const categoryRaw = this._setupCategoryBeforeUpdate(
categoryObject,
usedLanguage
);

async editCategory(categoryRaw) {
try {
await this._productsCategoryService
.update(this.currentCategory.id, categoryRaw)
Expand All @@ -92,33 +63,4 @@ export class CategoryEditComponent implements OnDestroy {
localeTranslate(member: ILocaleMember[]) {
return this._productLocalesService.getTranslate(member);
}

private _setupCategoryBeforeUpdate(
categoryObject,
usedLanguage: string
): IProductsCategoryCreateObject {
const newCategoryNames = this.currentCategory._nameLocaleValues.map(
({ locale, value }) => {
return locale === usedLanguage
? {
locale: usedLanguage,
value: categoryObject.name
}
: { locale, value };
}
);
if (!newCategoryNames.some((c) => c.locale === usedLanguage)) {
newCategoryNames.push({
locale: usedLanguage,
value: categoryObject.name
});
}

const categoryRaw: IProductsCategoryCreateObject = {
name: newCategoryNames,
image: categoryObject.image
};

return categoryRaw;
}
}
Expand Up @@ -71,24 +71,28 @@ export class BasicInfoFormComponent implements OnInit, AfterViewInit {
return this.image && this.image.value !== '';
}

get createObject() {
get usedLanguage() {
let usedLanguage = this._langTranslateService.currentLang;
switch (usedLanguage) {
case 'en':
usedLanguage += '-US';
break;
return (usedLanguage += '-US');

case 'bg':
usedLanguage += '-BG';
break;
return (usedLanguage += '-BG');

case 'he':
usedLanguage += '-IL';
break;
return (usedLanguage += '-IL');

case 'ru':
usedLanguage += '-RU';
break;
return (usedLanguage += '-RU');

default:
usedLanguage = 'en-US';
return 'en-US';
}
}

get createObject() {
const usedLanguage = this.usedLanguage;

const categoryObject: IProductsCategoryCreateObject = {
name: [{ locale: usedLanguage, value: this.name.value }]
Expand All @@ -100,16 +104,31 @@ export class BasicInfoFormComponent implements OnInit, AfterViewInit {
return categoryObject;
}

get editObject() {
const editObject = {
name: this.name.value
};

if (this.showImageMeta) {
editObject['image'] = this.image.value;
getEditObject(currentCategory) {
const usedLanguage = this.usedLanguage;
const newCategoryNames = currentCategory._nameLocaleValues.map(
({ locale, value }) => {
return locale === usedLanguage
? {
locale: usedLanguage,
value: this.name.value
}
: { locale, value };
}
);
if (!newCategoryNames.some((c) => c.locale === usedLanguage)) {
newCategoryNames.push({
locale: usedLanguage,
value: this.name.value
});
}

return editObject;
const categoryRaw: IProductsCategoryCreateObject = {
name: newCategoryNames,
image: this.image.value
};

return categoryRaw;
}

ngOnInit() {
Expand Down

0 comments on commit 032d300

Please sign in to comment.