ts-glitter 17.2.8 → 17.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ import { ApiShop } from '../../glitter-base/route/shopping.js';
11
11
  import { Tool } from '../../modules/tool.js';
12
12
  import { PdClass } from './pd-class.js';
13
13
  import { Ad } from '../public/ad.js';
14
- import { Language } from "../../glitter-base/global/language.js";
14
+ import { Language } from '../../glitter-base/global/language.js';
15
15
  const html = String.raw;
16
16
  export class ProductList {
17
17
  static arrowDownDataImage(color) {
@@ -127,14 +127,13 @@ export class ProductList {
127
127
  obj.gvc.glitter.closeDrawer();
128
128
  })}"
129
129
  >
130
-
131
130
  ${obj.title}
132
131
  </div>
133
132
  <div class="d-flex">
134
133
  <button class="box-tag-${obj.tag} arrow-icon-${text}"></button>
135
134
  </div>
136
135
  </div>
137
- <div class="box-inside-${text} ${obj.guideClass ? `box-inside-${obj.guideClass}` : ''} " >${obj.insideHTML}</div>
136
+ <div class="box-inside-${text} ${obj.guideClass ? `box-inside-${obj.guideClass}` : ''} ">${obj.insideHTML}</div>
138
137
  </div>`;
139
138
  }
140
139
  static spinner() {
@@ -245,7 +244,7 @@ export class ProductList {
245
244
  return code;
246
245
  }
247
246
  })(),
248
- language_data: language_data
247
+ language_data: language_data,
249
248
  };
250
249
  if (flattenedCol.title.includes(vm.query) ||
251
250
  flattenedCol.parentTitles.find((title) => {
@@ -257,14 +256,17 @@ export class ProductList {
257
256
  flattened.push(flattenedCol);
258
257
  }
259
258
  if (array.length) {
260
- flattened = flattened.concat(flattenCollections(array, [...parentTitles, (() => {
259
+ flattened = flattened.concat(flattenCollections(array, [
260
+ ...parentTitles,
261
+ (() => {
261
262
  if (language_data && language_data[Language.getLanguage()] && language_data[Language.getLanguage()].title) {
262
263
  return language_data[Language.getLanguage()].title;
263
264
  }
264
265
  else {
265
266
  return title;
266
267
  }
267
- })()], topLevelCollections));
268
+ })(),
269
+ ], topLevelCollections));
268
270
  }
269
271
  });
270
272
  return flattened;
@@ -389,17 +391,18 @@ export class ProductList {
389
391
  if (item.subCollections.length > 0) {
390
392
  for (const col of vm.collections) {
391
393
  if (item.subCollections.includes(col.title) && col.parentTitles[0] === item.title) {
392
- subHTML += html `<ul class="mt-1 pt-2 mx-n4 px-4 mb-n2 pb-2 box-item" style="${(decodeURIComponent((glitter.getUrlParameter('page') || '').split('/').reverse()[0]) === (col.code || col.title)) ? `background:#f5f5f5;` : ``}" onclick="${gvc.event(() => {
394
+ subHTML += html `<ul
395
+ class="mt-1 pt-2 mx-n4 px-4 mb-n2 pb-2 box-item"
396
+ style="${decodeURIComponent((glitter.getUrlParameter('page') || '').split('/').reverse()[0]) === (col.code || col.title)
397
+ ? `background:#f5f5f5;`
398
+ : ``}"
399
+ onclick="${gvc.event(() => {
393
400
  changePage(`collections/${col.code || col.title}`, 'page', {});
394
401
  gvc.glitter.closeDrawer();
395
- })}">
402
+ })}"
403
+ >
396
404
  <li style="font-weight: 500; line-height: 40px;">
397
- <div
398
- class="d-flex tx_700"
399
- style="color: ${fontColor};"
400
- >
401
- ${col.title}
402
- </div>
405
+ <div class="d-flex tx_700" style="color: ${fontColor};">${col.title}</div>
403
406
  </li>
404
407
  </ul>`;
405
408
  }
@@ -423,11 +426,15 @@ export class ProductList {
423
426
  length: item.subCollections.length,
424
427
  changePage,
425
428
  fontColor,
426
- openOnInit: [item.code].concat(vm.collections.filter((col) => {
429
+ openOnInit: [item.code]
430
+ .concat(vm.collections
431
+ .filter((col) => {
427
432
  return item.subCollections.includes(col.title) && col.parentTitles[0] === item.title;
428
- }).map((dd) => {
433
+ })
434
+ .map((dd) => {
429
435
  return dd.code || dd.title;
430
- })).includes(decodeURIComponent((glitter.getUrlParameter('page') || '').split('/').reverse()[0]))
436
+ }))
437
+ .includes(decodeURIComponent((glitter.getUrlParameter('page') || '').split('/').reverse()[0])),
431
438
  })
432
439
  : html `<div
433
440
  class="d-flex tx_700"
@@ -486,8 +493,8 @@ export class ProductList {
486
493
  else {
487
494
  let collectionObj = vm.collections.find((item) => {
488
495
  const language_data = item.language_data && item.language_data[Language.getLanguage()];
489
- const code = ((language_data && language_data.seo && language_data.seo.domain) || item.code) || (language_data && language_data.title) || item.title;
490
- return (code) === decodeURIComponent(extractCategoryTitleFromUrl(location.href));
496
+ const code = (language_data && language_data.seo && language_data.seo.domain) || item.code || (language_data && language_data.title) || item.title;
497
+ return code === decodeURIComponent(extractCategoryTitleFromUrl(location.href));
491
498
  });
492
499
  try {
493
500
  if (!collectionObj) {
@@ -499,7 +506,7 @@ export class ProductList {
499
506
  catch (e) { }
500
507
  if (collectionObj) {
501
508
  const language_data = collectionObj.language_data;
502
- vm.title = (language_data && (language_data[Language.getLanguage()] && language_data[Language.getLanguage()].title)) || collectionObj.title;
509
+ vm.title = (language_data && language_data[Language.getLanguage()] && language_data[Language.getLanguage()].title) || collectionObj.title;
503
510
  }
504
511
  else {
505
512
  vm.title = all_text;
@@ -621,6 +628,7 @@ export class ProductList {
621
628
  })}"
622
629
  >
623
630
  <option value="time">${Language.text('sort_by_date')}</option>
631
+ <option value="sales_desc">${Language.text('sort_by_sales_desc')}</option>
624
632
  <option value="min_price">${Language.text('sort_by_price_asc')}</option>
625
633
  <option value="max_price">${Language.text('sort_by_price_desc')}</option>
626
634
  </select>
@@ -3,7 +3,7 @@ import { ApiShop } from '../../glitter-base/route/shopping.js';
3
3
  import { Tool } from '../../modules/tool.js';
4
4
  import { PdClass } from './pd-class.js';
5
5
  import { Ad } from '../public/ad.js';
6
- import {Language} from "../../glitter-base/global/language.js";
6
+ import { Language } from '../../glitter-base/global/language.js';
7
7
 
8
8
  /*
9
9
  * Page: sy01_pd_collection
@@ -18,12 +18,12 @@ type Product = {
18
18
  };
19
19
  };
20
20
  interface LanguageData {
21
- title: string,
21
+ title: string;
22
22
  seo: {
23
23
  domain: string;
24
24
  title: string;
25
25
  content: string;
26
- }
26
+ };
27
27
  }
28
28
  type Collection = {
29
29
  title: string;
@@ -37,7 +37,7 @@ type Collection = {
37
37
  seo_content: string;
38
38
  seo_image: string;
39
39
  checked: boolean;
40
- language_data:LanguageData
40
+ language_data: LanguageData;
41
41
  };
42
42
 
43
43
  export class ProductList {
@@ -117,7 +117,7 @@ export class ProductList {
117
117
  }
118
118
  }
119
119
  `);
120
- return html` <div class="box-tag-${obj.tag} box-container-${text} ${obj.openOnInit ? `open-box`:''}">
120
+ return html` <div class="box-tag-${obj.tag} box-container-${text} ${obj.openOnInit ? `open-box` : ''}">
121
121
  <div
122
122
  class="box-navbar-${text} ${obj.guideClass ?? ''}"
123
123
  onclick="${obj.gvc.event((e) => {
@@ -165,14 +165,13 @@ export class ProductList {
165
165
  obj.gvc.glitter.closeDrawer();
166
166
  })}"
167
167
  >
168
-
169
168
  ${obj.title}
170
169
  </div>
171
170
  <div class="d-flex">
172
171
  <button class="box-tag-${obj.tag} arrow-icon-${text}"></button>
173
172
  </div>
174
173
  </div>
175
- <div class="box-inside-${text} ${obj.guideClass ? `box-inside-${obj.guideClass}` : ''} " >${obj.insideHTML}</div>
174
+ <div class="box-inside-${text} ${obj.guideClass ? `box-inside-${obj.guideClass}` : ''} ">${obj.insideHTML}</div>
176
175
  </div>`;
177
176
  }
178
177
 
@@ -384,13 +383,13 @@ export class ProductList {
384
383
  const flattenCollections = (collections: Collection[], parentTitles: string[] = [], topLevelCollections: string[] = []): Collection[] => {
385
384
  let flattened: Collection[] = [];
386
385
  collections.forEach((col) => {
387
- const { title, array, product_id, seo_title, seo_content, seo_image, code,language_data } = col;
386
+ const { title, array, product_id, seo_title, seo_content, seo_image, code, language_data } = col;
388
387
  const flattenedCol: Collection = {
389
- title:(()=>{
390
- if(language_data && (language_data as any)[Language.getLanguage()] && (language_data as any)[Language.getLanguage()].title){
391
- return (language_data as any)[Language.getLanguage()].title
392
- }else{
393
- return title
388
+ title: (() => {
389
+ if (language_data && (language_data as any)[Language.getLanguage()] && (language_data as any)[Language.getLanguage()].title) {
390
+ return (language_data as any)[Language.getLanguage()].title;
391
+ } else {
392
+ return title;
394
393
  }
395
394
  })(),
396
395
  array: [],
@@ -398,25 +397,27 @@ export class ProductList {
398
397
  checked: false,
399
398
  parentTitles: parentTitles.length ? [...parentTitles] : [],
400
399
  allCollections: parentTitles.length ? [...topLevelCollections] : [],
401
- subCollections: array.map((subCol) => (()=>{
402
- const language_data=subCol.language_data
403
- if(language_data && (language_data as any)[Language.getLanguage()] && (language_data as any)[Language.getLanguage()].title){
404
- return (language_data as any)[Language.getLanguage()].title
405
- }else{
406
- return subCol.title
407
- }
408
- })()),
400
+ subCollections: array.map((subCol) =>
401
+ (() => {
402
+ const language_data = subCol.language_data;
403
+ if (language_data && (language_data as any)[Language.getLanguage()] && (language_data as any)[Language.getLanguage()].title) {
404
+ return (language_data as any)[Language.getLanguage()].title;
405
+ } else {
406
+ return subCol.title;
407
+ }
408
+ })()
409
+ ),
409
410
  seo_title: seo_title,
410
411
  seo_content: seo_content,
411
412
  seo_image: seo_image,
412
- code: (()=>{
413
- if(language_data && (language_data as any)[Language.getLanguage()] && (language_data as any)[Language.getLanguage()].title){
414
- return (language_data as any)[Language.getLanguage()].seo.domain
415
- }else{
416
- return code
413
+ code: (() => {
414
+ if (language_data && (language_data as any)[Language.getLanguage()] && (language_data as any)[Language.getLanguage()].title) {
415
+ return (language_data as any)[Language.getLanguage()].seo.domain;
416
+ } else {
417
+ return code;
417
418
  }
418
419
  })(),
419
- language_data:language_data
420
+ language_data: language_data,
420
421
  };
421
422
  if (
422
423
  flattenedCol.title.includes(vm.query) ||
@@ -430,13 +431,22 @@ export class ProductList {
430
431
  flattened.push(flattenedCol);
431
432
  }
432
433
  if (array.length) {
433
- flattened = flattened.concat(flattenCollections(array, [...parentTitles, (()=>{
434
- if(language_data && (language_data as any)[Language.getLanguage()] && (language_data as any)[Language.getLanguage()].title){
435
- return (language_data as any)[Language.getLanguage()].title
436
- }else{
437
- return title
438
- }
439
- })()], topLevelCollections));
434
+ flattened = flattened.concat(
435
+ flattenCollections(
436
+ array,
437
+ [
438
+ ...parentTitles,
439
+ (() => {
440
+ if (language_data && (language_data as any)[Language.getLanguage()] && (language_data as any)[Language.getLanguage()].title) {
441
+ return (language_data as any)[Language.getLanguage()].title;
442
+ } else {
443
+ return title;
444
+ }
445
+ })(),
446
+ ],
447
+ topLevelCollections
448
+ )
449
+ );
440
450
  }
441
451
  });
442
452
  return flattened;
@@ -457,14 +467,16 @@ export class ProductList {
457
467
  });
458
468
  });
459
469
 
460
- const topLevelCollections = data.collections.map((col) => (()=>{
461
- const language_data=col.language_data
462
- if(language_data && (language_data as any)[Language.getLanguage()] && (language_data as any)[Language.getLanguage()].title){
463
- return (language_data as any)[Language.getLanguage()].title
464
- }else{
465
- return col.title
466
- }
467
- })());
470
+ const topLevelCollections = data.collections.map((col) =>
471
+ (() => {
472
+ const language_data = col.language_data;
473
+ if (language_data && (language_data as any)[Language.getLanguage()] && (language_data as any)[Language.getLanguage()].title) {
474
+ return (language_data as any)[Language.getLanguage()].title;
475
+ } else {
476
+ return col.title;
477
+ }
478
+ })()
479
+ );
468
480
  return flattenCollections(data.collections, [], topLevelCollections);
469
481
  }
470
482
 
@@ -558,29 +570,34 @@ export class ProductList {
558
570
  .map((item: any, index: number) => {
559
571
  let subHTML = '';
560
572
  if (item.subCollections.length > 0) {
561
-
562
573
  for (const col of vm.collections) {
563
574
  if (item.subCollections.includes(col.title) && col.parentTitles[0] === item.title) {
564
- subHTML += html`<ul class="mt-1 pt-2 mx-n4 px-4 mb-n2 pb-2 box-item" style="${(decodeURIComponent((glitter.getUrlParameter('page') || '').split('/').reverse()[0])===(col.code || col.title)) ? `background:#f5f5f5;`:``}" onclick="${gvc.event(() => {
565
- changePage(`collections/${col.code || col.title}` , 'page', {});
566
- gvc.glitter.closeDrawer();
567
- })}">
575
+ subHTML += html`<ul
576
+ class="mt-1 pt-2 mx-n4 px-4 mb-n2 pb-2 box-item"
577
+ style="${decodeURIComponent((glitter.getUrlParameter('page') || '').split('/').reverse()[0]) === (col.code || col.title)
578
+ ? `background:#f5f5f5;`
579
+ : ``}"
580
+ onclick="${gvc.event(() => {
581
+ changePage(`collections/${col.code || col.title}`, 'page', {});
582
+ gvc.glitter.closeDrawer();
583
+ })}"
584
+ >
568
585
  <li style="font-weight: 500; line-height: 40px;">
569
- <div
570
- class="d-flex tx_700"
571
- style="color: ${fontColor};"
572
- >
573
- ${col.title}
574
- </div>
586
+ <div class="d-flex tx_700" style="color: ${fontColor};">${col.title}</div>
575
587
  </li>
576
588
  </ul>`;
577
589
  }
578
590
  }
579
591
  }
580
- console.log(`in--->`,[item.code].concat( vm.collections.filter((col:any)=>{
581
- return item.subCollections.includes(col.title) && col.parentTitles[0] === item.title
582
- })))
583
- console.log(`in--->cludes->`,decodeURIComponent((glitter.getUrlParameter('page') || '').split('/').reverse()[0]))
592
+ console.log(
593
+ `in--->`,
594
+ [item.code].concat(
595
+ vm.collections.filter((col: any) => {
596
+ return item.subCollections.includes(col.title) && col.parentTitles[0] === item.title;
597
+ })
598
+ )
599
+ );
600
+ console.log(`in--->cludes->`, decodeURIComponent((glitter.getUrlParameter('page') || '').split('/').reverse()[0]));
584
601
  return html` <li
585
602
  class="${index + 1 === cols.length ? '' : 'border-bottom'}"
586
603
  style="${item.subCollections.length > 0 ? '' : 'padding: 16px;'} cursor: pointer;"
@@ -595,17 +612,22 @@ export class ProductList {
595
612
  length: item.subCollections.length,
596
613
  changePage,
597
614
  fontColor,
598
- openOnInit:[item.code].concat( vm.collections.filter((col:any)=>{
599
- return item.subCollections.includes(col.title) && col.parentTitles[0] === item.title
600
- }).map((dd:any)=>{
601
- return dd.code || dd.title
602
- })).includes(decodeURIComponent((glitter.getUrlParameter('page') || '').split('/').reverse()[0]))
615
+ openOnInit: [item.code]
616
+ .concat(
617
+ vm.collections
618
+ .filter((col: any) => {
619
+ return item.subCollections.includes(col.title) && col.parentTitles[0] === item.title;
620
+ })
621
+ .map((dd: any) => {
622
+ return dd.code || dd.title;
623
+ })
624
+ )
625
+ .includes(decodeURIComponent((glitter.getUrlParameter('page') || '').split('/').reverse()[0])),
603
626
  })
604
627
  : html`<div
605
628
  class="d-flex tx_700"
606
629
  style="color: ${fontColor};"
607
630
  onclick="${gvc.event(() => {
608
-
609
631
  changePage('collections/' + item.code, 'page', {});
610
632
  gvc.glitter.closeDrawer();
611
633
  })}"
@@ -656,23 +678,23 @@ export class ProductList {
656
678
  if (!vm.collections || vm.collections.length === 0) {
657
679
  vm.title = all_text;
658
680
  } else {
659
- let collectionObj = vm.collections.find((item:any) => {
660
- const language_data=item.language_data && item.language_data[Language.getLanguage()]
661
- const code=((language_data && language_data.seo && language_data.seo.domain) || item.code) || (language_data && language_data.title) || item.title;
662
- return (code) === decodeURIComponent(extractCategoryTitleFromUrl(location.href)) ;
681
+ let collectionObj = vm.collections.find((item: any) => {
682
+ const language_data = item.language_data && item.language_data[Language.getLanguage()];
683
+ const code = (language_data && language_data.seo && language_data.seo.domain) || item.code || (language_data && language_data.title) || item.title;
684
+ return code === decodeURIComponent(extractCategoryTitleFromUrl(location.href));
663
685
  });
664
686
  try {
665
- if(!collectionObj){
666
- collectionObj = vm.collections.find((item: { code: string,title:string }) => {
667
- return item.title === decodeURIComponent(extractCategoryTitleFromUrl(location.href)) ;
687
+ if (!collectionObj) {
688
+ collectionObj = vm.collections.find((item: { code: string; title: string }) => {
689
+ return item.title === decodeURIComponent(extractCategoryTitleFromUrl(location.href));
668
690
  });
669
691
  }
670
- }catch (e){}
671
- if(collectionObj){
672
- const language_data=collectionObj.language_data
673
- vm.title=(language_data && (language_data[Language.getLanguage()] && language_data[Language.getLanguage()].title)) || collectionObj.title;
674
- }else{
675
- vm.title=all_text
692
+ } catch (e) {}
693
+ if (collectionObj) {
694
+ const language_data = collectionObj.language_data;
695
+ vm.title = (language_data && language_data[Language.getLanguage()] && language_data[Language.getLanguage()].title) || collectionObj.title;
696
+ } else {
697
+ vm.title = all_text;
676
698
  }
677
699
  }
678
700
  gvc.notifyDataChange(ids.pageTitle);
@@ -689,8 +711,9 @@ export class ProductList {
689
711
 
690
712
  function findObjectByValue(arr: any, value: string): any {
691
713
  for (const item of arr) {
692
- const language_data=item.language_data
693
- const code=(language_data && language_data[Language.getLanguage()] && language_data[Language.getLanguage()].seo && language_data[Language.getLanguage()].seo.domain) || item.code
714
+ const language_data = item.language_data;
715
+ const code =
716
+ (language_data && language_data[Language.getLanguage()] && language_data[Language.getLanguage()].seo && language_data[Language.getLanguage()].seo.domain) || item.code;
694
717
  if (code === value) {
695
718
  return item;
696
719
  }
@@ -733,8 +756,8 @@ export class ProductList {
733
756
  });
734
757
  }
735
758
  }
736
- }catch (e) {
737
- console.log(e)
759
+ } catch (e) {
760
+ console.log(e);
738
761
  }
739
762
  }
740
763
 
@@ -796,6 +819,7 @@ export class ProductList {
796
819
  })}"
797
820
  >
798
821
  <option value="time">${Language.text('sort_by_date')}</option>
822
+ <option value="sales_desc">${Language.text('sort_by_sales_desc')}</option>
799
823
  <option value="min_price">${Language.text('sort_by_price_asc')}</option>
800
824
  <option value="max_price">${Language.text('sort_by_price_desc')}</option>
801
825
  </select>
@@ -839,7 +863,7 @@ export class ProductList {
839
863
  vm.pageIndex = p;
840
864
  loadings.product = true;
841
865
  gvc.notifyDataChange(ids.product);
842
- (document.querySelector('html') as any).scrollTo(0,0);
866
+ (document.querySelector('html') as any).scrollTo(0, 0);
843
867
  })}
844
868
  <div style="margin-top: 240px;"></div>`;
845
869
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-glitter",
3
- "version": "17.2.8",
3
+ "version": "17.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -849,6 +849,8 @@ router.get('/product', async (req, resp) => {
849
849
  return ``;
850
850
  case 'stock_asc':
851
851
  return ``;
852
+ case 'sales_desc':
853
+ return `order by (content->>'$.total_sales') desc`;
852
854
  case 'default':
853
855
  default:
854
856
  return `order by id desc`;