@spartacus/cart
Version:
`@spartacus/cart` is a package that you can include in your application, which allows you to use various cart features.
783 lines (771 loc) • 76.1 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@spartacus/storefront'), require('rxjs'), require('rxjs/operators'), require('@spartacus/core'), require('@spartacus/cart/import-export/core'), require('@angular/common'), require('@angular/router'), require('@angular/forms')) :
typeof define === 'function' && define.amd ? define('@spartacus/cart/import-export/components', ['exports', '@angular/core', '@spartacus/storefront', 'rxjs', 'rxjs/operators', '@spartacus/core', '@spartacus/cart/import-export/core', '@angular/common', '@angular/router', '@angular/forms'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.spartacus = global.spartacus || {}, global.spartacus.cart = global.spartacus.cart || {}, global.spartacus.cart['import-export'] = global.spartacus.cart['import-export'] || {}, global.spartacus.cart['import-export'].components = {}), global.ng.core, global.storefront, global.rxjs, global.rxjs.operators, global.core, global.spartacus.cart['import-export'].core, global.ng.common, global.ng.router, global.ng.forms));
}(this, (function (exports, i0, i1, rxjs, operators, i3, i3$1, i2, router, i6) { 'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
var i3__namespace$1 = /*#__PURE__*/_interopNamespace(i3);
var i3__namespace = /*#__PURE__*/_interopNamespace(i3$1);
var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
var i6__namespace = /*#__PURE__*/_interopNamespace(i6);
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || from);
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}
function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m")
throw new TypeError("Private method is not writable");
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
}
var ExportOrderEntriesToCsvService = /** @class */ (function () {
function ExportOrderEntriesToCsvService(exportCsvFileService, importExportConfig, globalMessageService, translationService) {
var _a, _b;
this.exportCsvFileService = exportCsvFileService;
this.importExportConfig = importExportConfig;
this.globalMessageService = globalMessageService;
this.translationService = translationService;
this.columns = __spreadArray([
{
name: {
key: 'code',
},
value: 'product.code',
},
{
name: {
key: 'quantity',
},
value: 'quantity',
}
], __read(((_b = (_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.additionalColumns) !== null && _b !== void 0 ? _b : [])));
}
Object.defineProperty(ExportOrderEntriesToCsvService.prototype, "exportConfig", {
get: function () {
var _a;
return (_a = this.importExportConfig.cartImportExport) === null || _a === void 0 ? void 0 : _a.export;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ExportOrderEntriesToCsvService.prototype, "separator", {
get: function () {
var _a;
return (_a = this.importExportConfig.cartImportExport) === null || _a === void 0 ? void 0 : _a.file.separator;
},
enumerable: false,
configurable: true
});
ExportOrderEntriesToCsvService.prototype.downloadCsv = function (entries) {
var _this = this;
this.getResolvedEntries(entries)
.pipe(operators.take(1))
.subscribe(function (csvData) { return _this.download(csvData); });
};
ExportOrderEntriesToCsvService.prototype.resolveValue = function (combinedKeys, entry) {
var _a, _b;
return ((_b = (_a = combinedKeys
.split('.')
.reduce(function (obj, key) { return (obj ? obj[key] : ''); }, entry)) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '');
};
ExportOrderEntriesToCsvService.prototype.resolveValues = function (entries) {
var _this = this;
return entries.map(function (entry) { return _this.columns.map(function (column) { return _this.resolveValue(column.value, entry); }); });
};
ExportOrderEntriesToCsvService.prototype.getTranslatedColumnHeaders = function () {
var _this = this;
return rxjs.combineLatest(this.columns.map(function (column) { return _this.translationService.translate("exportEntries.columnNames." + column.name.key); }));
};
ExportOrderEntriesToCsvService.prototype.displayExportMessage = function () {
this.globalMessageService.add({ key: 'exportEntries.exportMessage' }, i3.GlobalMessageType.MSG_TYPE_INFO);
};
ExportOrderEntriesToCsvService.prototype.limitValues = function (data) {
var _a, _b;
return ((_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.maxEntries)
? data.splice(0, (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.maxEntries)
: data;
};
ExportOrderEntriesToCsvService.prototype.getResolvedEntries = function (entries) {
var values = this.limitValues(this.resolveValues(entries));
return this.getTranslatedColumnHeaders().pipe(operators.map(function (headers) {
return __spreadArray([headers], __read(values));
}));
};
ExportOrderEntriesToCsvService.prototype.download = function (entries) {
var _this = this;
var _a, _b, _c;
if ((_a = this.exportConfig) === null || _a === void 0 ? void 0 : _a.messageEnabled) {
this.displayExportMessage();
}
setTimeout(function () {
if (_this.exportConfig !== undefined && _this.separator !== undefined) {
_this.exportCsvFileService.download(entries, _this.separator, _this.exportConfig.fileOptions);
}
}, (_c = (_b = this.exportConfig) === null || _b === void 0 ? void 0 : _b.downloadDelay) !== null && _c !== void 0 ? _c : 0);
};
return ExportOrderEntriesToCsvService;
}());
ExportOrderEntriesToCsvService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ExportOrderEntriesToCsvService, deps: [{ token: i1__namespace.ExportCsvFileService }, { token: i3__namespace.ImportExportConfig }, { token: i3__namespace$1.GlobalMessageService }, { token: i3__namespace$1.TranslationService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
ExportOrderEntriesToCsvService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ExportOrderEntriesToCsvService, providedIn: 'root' });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ExportOrderEntriesToCsvService, decorators: [{
type: i0.Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: function () { return [{ type: i1__namespace.ExportCsvFileService }, { type: i3__namespace.ImportExportConfig }, { type: i3__namespace$1.GlobalMessageService }, { type: i3__namespace$1.TranslationService }]; } });
var ExportOrderEntriesComponent = /** @class */ (function () {
function ExportOrderEntriesComponent(exportEntriesService, contextService) {
this.exportEntriesService = exportEntriesService;
this.contextService = contextService;
this.orderEntriesContext$ = this.contextService.get(i1.ORDER_ENTRIES_CONTEXT);
this.entries$ = this.orderEntriesContext$.pipe(operators.switchMap(function (orderEntriesContext) { var _a, _b; return (_b = (_a = orderEntriesContext === null || orderEntriesContext === void 0 ? void 0 : orderEntriesContext.getEntries) === null || _a === void 0 ? void 0 : _a.call(orderEntriesContext)) !== null && _b !== void 0 ? _b : rxjs.of(undefined); }));
}
ExportOrderEntriesComponent.prototype.exportCsv = function (entries) {
this.exportEntriesService.downloadCsv(entries);
};
return ExportOrderEntriesComponent;
}());
ExportOrderEntriesComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ExportOrderEntriesComponent, deps: [{ token: ExportOrderEntriesToCsvService }, { token: i1__namespace.ContextService }], target: i0__namespace.ɵɵFactoryTarget.Component });
ExportOrderEntriesComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: ExportOrderEntriesComponent, selector: "cx-export-order-entries", ngImport: i0__namespace, template: "<button\n *ngIf=\"(entries$ | async)?.length > 0 && (entries$ | async) as entries\"\n class=\"link cx-action-link\"\n (click)=\"exportCsv(entries)\"\n>\n {{ 'exportEntries.exportToCsv' | cxTranslate }}\n</button>\n", directives: [{ type: i2__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "async": i2__namespace.AsyncPipe, "cxTranslate": i3__namespace$1.TranslatePipe }, changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ExportOrderEntriesComponent, decorators: [{
type: i0.Component,
args: [{
selector: 'cx-export-order-entries',
templateUrl: './export-order-entries.component.html',
changeDetection: i0.ChangeDetectionStrategy.OnPush,
}]
}], ctorParameters: function () { return [{ type: ExportOrderEntriesToCsvService }, { type: i1__namespace.ContextService }]; } });
var ExportOrderEntriesModule = /** @class */ (function () {
function ExportOrderEntriesModule() {
}
return ExportOrderEntriesModule;
}());
ExportOrderEntriesModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ExportOrderEntriesModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
ExportOrderEntriesModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ExportOrderEntriesModule, declarations: [ExportOrderEntriesComponent], imports: [i2.CommonModule,
router.RouterModule,
i3.I18nModule,
i3.UrlModule, i3__namespace$1.ConfigModule], exports: [ExportOrderEntriesComponent] });
ExportOrderEntriesModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ExportOrderEntriesModule, imports: [[
i2.CommonModule,
router.RouterModule,
i3.I18nModule,
i3.UrlModule,
i3.ConfigModule.withConfig({
cmsComponents: {
ExportOrderEntriesComponent: {
component: ExportOrderEntriesComponent,
},
},
}),
]] });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ExportOrderEntriesModule, decorators: [{
type: i0.NgModule,
args: [{
imports: [
i2.CommonModule,
router.RouterModule,
i3.I18nModule,
i3.UrlModule,
i3.ConfigModule.withConfig({
cmsComponents: {
ExportOrderEntriesComponent: {
component: ExportOrderEntriesComponent,
},
},
}),
],
exports: [ExportOrderEntriesComponent],
declarations: [ExportOrderEntriesComponent],
entryComponents: [ExportOrderEntriesComponent],
}]
}] });
var ImportOrderEntriesComponent = /** @class */ (function () {
function ImportOrderEntriesComponent(launchDialogService, contextService) {
this.launchDialogService = launchDialogService;
this.contextService = contextService;
this.subscription = new rxjs.Subscription();
this.orderEntriesContext$ = this.contextService.get(i1.ORDER_ENTRIES_CONTEXT);
}
ImportOrderEntriesComponent.prototype.openDialog = function (orderEntriesContext) {
this.launchDialogService.openDialogAndSubscribe("IMPORT_TO_CART" /* IMPORT_TO_CART */, this.element, { orderEntriesContext: orderEntriesContext });
};
return ImportOrderEntriesComponent;
}());
ImportOrderEntriesComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ImportOrderEntriesComponent, deps: [{ token: i1__namespace.LaunchDialogService }, { token: i1__namespace.ContextService }], target: i0__namespace.ɵɵFactoryTarget.Component });
ImportOrderEntriesComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: ImportOrderEntriesComponent, selector: "cx-import-order-entries", viewQueries: [{ propertyName: "element", first: true, predicate: ["open"], descendants: true }], ngImport: i0__namespace, template: "<button\n *ngIf=\"orderEntriesContext$ | async as orderEntriesContext\"\n class=\"link cx-action-link\"\n (click)=\"openDialog(orderEntriesContext)\"\n>\n {{ 'importEntries.importProducts' | cxTranslate }}\n</button>\n", directives: [{ type: i2__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "async": i2__namespace.AsyncPipe, "cxTranslate": i3__namespace$1.TranslatePipe }, changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ImportOrderEntriesComponent, decorators: [{
type: i0.Component,
args: [{
selector: 'cx-import-order-entries',
templateUrl: './import-order-entries.component.html',
changeDetection: i0.ChangeDetectionStrategy.OnPush,
}]
}], ctorParameters: function () { return [{ type: i1__namespace.LaunchDialogService }, { type: i1__namespace.ContextService }]; }, propDecorators: { element: [{
type: i0.ViewChild,
args: ['open']
}] } });
var ImportProductsFromCsvService = /** @class */ (function () {
function ImportProductsFromCsvService() {
}
ImportProductsFromCsvService.prototype.csvDataToProduct = function (csvData) {
return csvData.map(function (row) { return ({
productCode: row[0],
quantity: Number(row[1]),
}); });
};
ImportProductsFromCsvService.prototype.isDataParsableToProducts = function (data) {
var patternRegex = new RegExp(/(?:\s|^)\d+(?=\s|$)/);
return data.length > 0 && data.every(function (row) { return patternRegex.test(row[1]); });
};
return ImportProductsFromCsvService;
}());
ImportProductsFromCsvService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ImportProductsFromCsvService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
ImportProductsFromCsvService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ImportProductsFromCsvService, providedIn: 'root' });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ImportProductsFromCsvService, decorators: [{
type: i0.Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: function () { return []; } });
var ImportEntriesFormComponent = /** @class */ (function () {
function ImportEntriesFormComponent(launchDialogService, importToCartService, importCsvService, filesFormValidators, importExportConfig) {
this.launchDialogService = launchDialogService;
this.importToCartService = importToCartService;
this.importCsvService = importCsvService;
this.filesFormValidators = filesFormValidators;
this.importExportConfig = importExportConfig;
this.formSubmitSubject$ = new rxjs.Subject();
this.submitEvent = new i0.EventEmitter();
}
ImportEntriesFormComponent.prototype.ngOnInit = function () {
var _this = this;
this.form = this.buildForm();
this.formSubmitSubject$
.pipe(operators.tap(function () {
if (_this.form.invalid) {
_this.form.markAllAsTouched();
i1.FormUtils.deepUpdateValueAndValidity(_this.form);
}
}), operators.switchMap(function () {
var _a;
return _this.form.statusChanges.pipe(operators.startWith((_a = _this.form.get('file')) === null || _a === void 0 ? void 0 : _a.status), operators.filter(function (status) { return status !== 'PENDING'; }), operators.take(1));
}), operators.filter(function (status) { return status === 'VALID'; }))
.subscribe(function () {
_this.save();
});
};
ImportEntriesFormComponent.prototype.close = function (reason) {
this.launchDialogService.closeDialog(reason);
};
ImportEntriesFormComponent.prototype.save = function () {
var _this = this;
var _a, _b;
var file = (_b = (_a = this.form.get('file')) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b[0];
if (this.separator !== undefined) {
this.importCsvService
.loadFile(file, this.separator)
.subscribe(function (loadedFile) {
_this.submitEvent.emit({
products: _this.importToCartService.csvDataToProduct(loadedFile),
});
});
}
};
ImportEntriesFormComponent.prototype.buildForm = function () {
var _this = this;
var form = new i6.FormGroup({});
form.setControl('file', new i6.FormControl('', [i6.Validators.required, this.filesFormValidators.maxSize(this.maxSize)], [
function (control) { return _this.separator !== undefined
? _this.importCsvService.validateFile(control.value[0], {
separator: _this.separator,
isDataParsable: _this.importToCartService.isDataParsableToProducts,
maxEntries: _this.maxEntries,
})
: rxjs.of(null); },
]));
return form;
};
Object.defineProperty(ImportEntriesFormComponent.prototype, "allowedTypes", {
get: function () {
var _a, _b, _c;
return (_c = (_b = (_a = this.importExportConfig.cartImportExport) === null || _a === void 0 ? void 0 : _a.import) === null || _b === void 0 ? void 0 : _b.fileValidity) === null || _c === void 0 ? void 0 : _c.allowedTypes;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ImportEntriesFormComponent.prototype, "maxSize", {
get: function () {
var _a, _b, _c;
return (_c = (_b = (_a = this.importExportConfig.cartImportExport) === null || _a === void 0 ? void 0 : _a.import) === null || _b === void 0 ? void 0 : _b.fileValidity) === null || _c === void 0 ? void 0 : _c.maxSize;
},
enumerable: false,
configurable: true
});
Object.defineProperty(ImportEntriesFormComponent.prototype, "maxEntries", {
get: function () {
var _a, _b, _c, _d;
return (_d = (_c = (_b = (_a = this.importExportConfig.cartImportExport) === null || _a === void 0 ? void 0 : _a.import) === null || _b === void 0 ? void 0 : _b.fileValidity) === null || _c === void 0 ? void 0 : _c.maxEntries) === null || _d === void 0 ? void 0 : _d[this.type];
},
enumerable: false,
configurable: true
});
Object.defineProperty(ImportEntriesFormComponent.prototype, "separator", {
get: function () {
var _a;
return (_a = this.importExportConfig.cartImportExport) === null || _a === void 0 ? void 0 : _a.file.separator;
},
enumerable: false,
configurable: true
});
return ImportEntriesFormComponent;
}());
ImportEntriesFormComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ImportEntriesFormComponent, deps: [{ token: i1__namespace.LaunchDialogService }, { token: ImportProductsFromCsvService }, { token: i1__namespace.ImportCsvFileService }, { token: i1__namespace.FilesFormValidators }, { token: i3__namespace.ImportExportConfig }], target: i0__namespace.ɵɵFactoryTarget.Component });
ImportEntriesFormComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: ImportEntriesFormComponent, selector: "cx-import-entries-form", inputs: { type: "type" }, outputs: { submitEvent: "submitEvent" }, ngImport: i0__namespace, template: "<form *ngIf=\"form\" [formGroup]=\"form\" (submit)=\"formSubmitSubject$.next()\">\n <p class=\"cx-import-entries-subtitle\">\n {{ 'importEntriesDialog.importProductsSubtitle' | cxTranslate }}\n </p>\n <p>\n {{ 'importEntriesDialog.importProductFileDetails' | cxTranslate }}\n </p>\n <label>\n <cx-file-upload [formControl]=\"form.get('file')\" [accept]=\"allowedTypes\">\n {{ 'importEntriesDialog.selectFile' | cxTranslate }}\n </cx-file-upload>\n <cx-form-errors\n [control]=\"form.get('file')\"\n prefix=\"formErrors.file\"\n ></cx-form-errors>\n </label>\n <div class=\"cx-import-entries-footer\">\n <button\n (click)=\"close('Close Import Products Dialog')\"\n class=\"btn btn-action\"\n type=\"button\"\n >\n {{ 'importEntriesDialog.cancel' | cxTranslate }}\n </button>\n <button\n class=\"btn btn-primary\"\n type=\"submit\"\n [disabled]=\"form.get('file')?.status === 'PENDING'\"\n >\n {{ 'importEntriesDialog.upload' | cxTranslate }}\n </button>\n </div>\n</form>\n", components: [{ type: i1__namespace.FileUploadComponent, selector: "cx-file-upload", inputs: ["accept", "multiple"], outputs: ["update"] }, { type: i1__namespace.FormErrorsComponent, selector: "cx-form-errors", inputs: ["prefix", "translationParams", "control"] }], directives: [{ type: i2__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i6__namespace.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { type: i6__namespace.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { type: i6__namespace.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { type: i6__namespace.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i6__namespace.FormControlDirective, selector: "[formControl]", inputs: ["disabled", "formControl", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }], pipes: { "cxTranslate": i3__namespace$1.TranslatePipe }, changeDetection: i0__namespace.ChangeDetectionStrategy.OnPush });
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ImportEntriesFormComponent, decorators: [{
type: i0.Component,
args: [{
selector: 'cx-import-entries-form',
templateUrl: './import-entries-form.component.html',
changeDetection: i0.ChangeDetectionStrategy.OnPush,
}]
}], ctorParameters: function () { return [{ type: i1__namespace.LaunchDialogService }, { type: ImportProductsFromCsvService }, { type: i1__namespace.ImportCsvFileService }, { type: i1__namespace.FilesFormValidators }, { type: i3__namespace.ImportExportConfig }]; }, propDecorators: { submitEvent: [{
type: i0.Output
}], type: [{
type: i0.Input
}] } });
var ImportToNewSavedCartFormComponent = /** @class */ (function (_super) {
__extends(ImportToNewSavedCartFormComponent, _super);
function ImportToNewSavedCartFormComponent(launchDialogService, importToCartService, importCsvService, filesFormValidators, importExportConfig, datePipe) {
var _this = _super.call(this, launchDialogService, importToCartService, importCsvService, filesFormValidators, importExportConfig) || this;
_this.launchDialogService = launchDialogService;
_this.importToCartService = importToCartService;
_this.importCsvService = importCsvService;
_this.filesFormValidators = filesFormValidators;
_this.importExportConfig = importExportConfig;
_this.datePipe = datePipe;
_this.descriptionMaxLength = 250;
_this.nameMaxLength = 50;
_this.submitEvent = new i0.EventEmitter();
return _this;
}
Object.defineProperty(ImportToNewSavedCartFormComponent.prototype, "descriptionsCharacterLeft", {
get: function () {
var _a, _b;
return (this.descriptionMaxLength -
(((_b = (_a = this.form.get('description')) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.length) || 0));
},
enumerable: false,
configurable: true
});
ImportToNewSavedCartFormComponent.prototype.save = function () {
var _this = this;
var _a, _b;
var file = (_b = (_a = this.form.get('file')) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b[0];
if (this.separator !== undefined) {
this.importCsvService
.loadFile(file, this.separator)
.subscribe(function (loadedFile) {
var _a, _b;
_this.submitEvent.emit({
products: _this.importToCartService.csvDataToProduct(loadedFile),
savedCartInfo: {
name: (_a = _this.form.get('name')) === null || _a === void 0 ? void 0 : _a.value,
description: (_b = _this.form.get('description')) === null || _b === void 0 ? void 0 : _b.value,
},
});
});
}
};
ImportToNewSavedCartFormComponent.prototype.buildForm = function () {
var _this = this;
var form = new i6.FormGroup({});
form.setControl('file', new i6.FormControl('', [i6.Validators.required, this.filesFormValidators.maxSize(this.maxSize)], [
function (control) { return _this.separator !== undefined
? _this.importCsvService.validateFile(control.value[0], {
separator: _this.separator,
isDataParsable: _this.importToCartService.isDataParsableToProducts,
maxEntries: _this.maxEntries,
})
: rxjs.of(null); },
]));
form.setControl('name', new i6.FormControl('', [
i6.Validators.required,
i6.Validators.maxLength(this.nameMaxLength),
]));
form.setControl('description', new i6.FormControl('', [i6.Validators.maxLength(this.descriptionMaxLength)]));
return form;
};
ImportToNewSavedCartFormComponent.prototype.updateCartName = function () {
var _a;
var nameField = this.form.get('name');
if (nameField && !(nameField === null || nameField === void 0 ? void 0 : nameField.value) && ((_a = this.cartNameGeneration) === null || _a === void 0 ? void 0 : _a.source)) {
switch (this.cartNameGeneration.source) {
case i3$1.CartNameSource.FILE_NAME: {
this.setFieldValueByFileName(nameField);
break;
}
case i3$1.CartNameSource.DATE_TIME: {
this.setFieldValueByDatetime(nameField);
break;
}
default: {
break;
}
}
}
};
ImportToNewSavedCartFormComponent.prototype.setFieldValueByFileName = function (nameField) {
var _a, _b, _c, _d;
var fileName = (_d = (_c = (_b = (_a = this.form
.get('file')) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.replace(/\.[^/.]+$/, '');
nameField.setValue(fileName);
};
ImportToNewSavedCartFormComponent.prototype.setFieldValueByDatetime = function (nameField) {
var _a, _b, _c;
var date = new Date();
var fromDateOptions = (_a = this.cartNameGeneration) === null || _a === void 0 ? void 0 : _a.fromDateOptions;
var mask = fromDateOptions === null || fromDateOptions === void 0 ? void 0 : fromDateOptions.mask;
var prefix = (_b = fromDateOptions === null || fromDateOptions === void 0 ? void 0 : fromDateOptions.prefix) !== null && _b !== void 0 ? _b : '';
var suffix = (_c = fromDateOptions === null || fromDateOptions === void 0 ? void 0 : fromDateOptions.suffix) !== null && _c !== void 0 ? _c : '';
var dateString = mask
? this.datePipe.transform(date, mask)
: this.datePipe.transform(date);
nameField.setValue("" + prefix + dateString + suffix);
};
Object.defineProperty(ImportToNewSavedCartFormComponent.prototype, "cartNameGeneration", {
get: function () {
var _a, _b;
return (_b = (_a = this.importExportConfig.cartImportExport) === null || _a === void 0 ? void 0 : _a.import) === null || _b === void 0 ? void 0 : _b.cartNameGeneration;
},
enumerable: false,
configurable: true
});
return ImportToNewSavedCartFormComponent;
}(ImportEntriesFormComponent));
ImportToNewSavedCartFormComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: ImportToNewSavedCartFormComponent, deps: [{ token: i1__namespace.LaunchDialogService }, { token: ImportProductsFromCsvService }, { token: i1__namespace.ImportCsvFileService }, { token: i1__namespace.FilesFormValidators }, { token: i3__namespace.ImportExportConfig }, { token: i3__namespace$1.CxDatePipe }], target: i0__namespace.ɵɵFactoryTarget.Component });
ImportToNewSavedCartFormComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: ImportToNewSavedCartFormComponent, selector: "cx-import-to-new-saved-cart-form", outputs: { submitEvent: "submitEvent" }, providers: [i3.CxDatePipe], usesInheritance: true, ngImport: i0__namespace, template: "<form *ngIf=\"form\" [formGroup]=\"form\" (submit)=\"formSubmitSubject$.next()\">\n <p class=\"cx-import-entries-subtitle\">\n {{ 'importEntriesDialog.importProductsNewSavedCartSubtitle' | cxTranslate }}\n </p>\n <p>\n {{ 'importEntriesDialog.importProductFileDetails' | cxTranslate }}\n </p>\n <label>\n <cx-file-upload\n [formControl]=\"form.get('file')\"\n (update)=\"updateCartName()\"\n [accept]=\"allowedTypes\"\n >\n {{ 'importEntriesDialog.selectFile' | cxTranslate }}\n </cx-file-upload>\n <cx-form-errors\n [control]=\"form.get('file')\"\n prefix=\"formErrors.file\"\n ></cx-form-errors>\n </label>\n <div class=\"cx-import-entries-row\">\n <label>\n <span class=\"cx-import-entries-label label-content\">\n {{ 'importEntriesDialog.savedCartName' | cxTranslate }}\n </span>\n <input\n [maxLength]=\"nameMaxLength\"\n class=\"form-control\"\n formControlName=\"name\"\n required\n type=\"text\"\n />\n <cx-form-errors [control]=\"form.get('name')\"></cx-form-errors>\n </label>\n </div>\n\n <div class=\"cx-import-entries-row\">\n <label>\n <span class=\"cx-import-entries-label label-content\">\n {{ 'importEntriesDialog.savedCartDescription' | cxTranslate }}\n <span class=\"cx-import-entries-label-optional\">\n ({{ 'importEntriesDialog.optional' | cxTranslate }})\n </span></span\n >\n <textarea\n [maxLength]=\"descriptionMaxLength\"\n class=\"form-control\"\n formControlName=\"description\"\n rows=\"5\"\n ></textarea>\n <cx-form-errors [control]=\"form.get('description')\"></cx-form-errors>\n\n <p class=\"cx-import-entries-input-hint\">\n {{\n 'importEntriesDialog.charactersLeft'\n | cxTranslate: { count: descriptionsCharacterLeft }\n }}\n </p>\n </label>\n </div>\n <div class=\"cx-import-entries-footer\">\n <button\n (click)=\"close('Close Import Products Dialog')\"\n class=\"btn btn-action\"\n type=\"button\"\n >\n {{ 'importEntriesDialog.cancel' | cxTranslate }}\n </button>\n <button\n class=\"btn btn-primary\"\n type=\"submit\"\n [disabled]=\"form.get('file')?.status === 'PENDING'\"\n >\n {{ 'importEntriesDialog.upload' | cxTranslate }}\n </button>\n </div>\n</form>\n", components: [{ type: i1__namespace.FileUploadComponent, selector: "cx-fi