@glissandoo/lib 1.78.0 → 1.80.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.
@@ -1,7 +1,4 @@
1
- import { FileSectionId } from '../../models/Group/Repertory/File/Section/types';
2
- import { MusicStyleType } from '../musicStyles/index';
3
- export declare const orders: {
4
- [k: string]: FileSectionId[];
5
- };
6
- export declare const getOrderByMusicStyle: (musicStyle: MusicStyleType) => FileSectionId[];
7
- export declare const orderByMusicStyle: <T>(list: T[], field: keyof T, musicStyle: MusicStyleType) => T[];
1
+ import { FileSectionIdReserved } from '../../models/Group/Repertory/File/Section/types';
2
+ import { InstrumentId } from '../instruments';
3
+ export declare const getFileSectionsOrder: (instrumentsOrder: InstrumentId[]) => (InstrumentId | FileSectionIdReserved)[];
4
+ export declare const orderByInstruments: <T>(list: T[], field: keyof T, instrumentsOrder: InstrumentId[]) => T[];
@@ -1,20 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.orderByMusicStyle = exports.getOrderByMusicStyle = exports.orders = void 0;
3
+ exports.orderByInstruments = exports.getFileSectionsOrder = void 0;
4
4
  const types_1 = require("../../models/Group/Repertory/File/Section/types");
5
- const fileSections_1 = require("../fileSections");
6
- const orders_1 = require("../musicStyles/orders");
7
5
  const utils_1 = require("../utils");
8
- exports.orders = Object.fromEntries(Object.entries(orders_1.orders).map(([musicStyle, instruments]) => [
9
- musicStyle,
10
- [types_1.FileSectionIdReserved.All, ...instruments],
11
- ]));
12
- const getOrderByMusicStyle = (musicStyle) => {
13
- return musicStyle in exports.orders ? exports.orders[musicStyle] : fileSections_1.fileSectionIdList;
6
+ const getFileSectionsOrder = (instrumentsOrder) => [
7
+ types_1.FileSectionIdReserved.All,
8
+ ...instrumentsOrder,
9
+ ];
10
+ exports.getFileSectionsOrder = getFileSectionsOrder;
11
+ const orderByInstruments = (list, field, instrumentsOrder) => {
12
+ const fileSectionsOrder = (0, exports.getFileSectionsOrder)(instrumentsOrder);
13
+ return (0, utils_1.sortByMatch)(list, field, fileSectionsOrder);
14
14
  };
15
- exports.getOrderByMusicStyle = getOrderByMusicStyle;
16
- const orderByMusicStyle = (list, field, musicStyle) => {
17
- const order = (0, exports.getOrderByMusicStyle)(musicStyle);
18
- return (0, utils_1.sortByMatch)(list, field, order);
19
- };
20
- exports.orderByMusicStyle = orderByMusicStyle;
15
+ exports.orderByInstruments = orderByInstruments;
@@ -0,0 +1,2 @@
1
+ import { InstrumentId } from '.';
2
+ export declare const orderByInstruments: <T>(list: T[], field: keyof T, instrumentsOrder: InstrumentId[]) => T[];
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.orderByInstruments = void 0;
4
+ const utils_1 = require("../utils");
5
+ const orderByInstruments = (list, field, instrumentsOrder) => {
6
+ return (0, utils_1.sortByMatch)(list, field, instrumentsOrder);
7
+ };
8
+ exports.orderByInstruments = orderByInstruments;
@@ -1,12 +1,13 @@
1
+ import { VoteValue } from '../models/Group/Repertory/types';
1
2
  export declare const rateSteps: {
2
- id: string;
3
+ id: 'love' | 'like' | 'neutral' | 'dislike';
3
4
  emoji: string;
4
- value: number;
5
- range: number[];
5
+ value: VoteValue;
6
+ range: [number, number];
6
7
  }[];
7
8
  export declare const getStepRating: (rating: number) => {
8
- id: string;
9
+ id: 'love' | 'like' | 'neutral' | 'dislike';
9
10
  emoji: string;
10
- value: number;
11
- range: number[];
11
+ value: VoteValue;
12
+ range: [number, number];
12
13
  } | undefined;
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const date_fns_1 = require("date-fns");
7
7
  const lodash_1 = require("lodash");
8
8
  const orders_1 = require("../../helpers/musicStyles/orders");
9
- const utils_1 = require("../../helpers/utils");
10
9
  const lang_1 = require("../../lang");
11
10
  const basic_1 = __importDefault(require("./Player/basic"));
12
11
  const promoter_1 = __importDefault(require("./promoter"));
13
12
  const types_1 = require("./types");
13
+ const orders_2 = require("../../helpers/instruments/orders");
14
14
  class Evento extends promoter_1.default {
15
15
  constructor(doc, lang = lang_1.defaultLocale) {
16
16
  super(doc, lang);
@@ -141,7 +141,7 @@ class Evento extends promoter_1.default {
141
141
  }))
142
142
  : Object.entries(this.players).map(([id, player]) => new basic_1.default(this.id, { id, ...player }));
143
143
  const orderedPlayers = order
144
- ? (0, utils_1.sortByMatch)(players, 'mainInstrument', order)
144
+ ? (0, orders_2.orderByInstruments)(players, 'mainInstrument', order)
145
145
  : (0, orders_1.orderByMusicStyle)(players, 'mainInstrument', this.promoterInfo.musicStyle);
146
146
  if (showAll)
147
147
  return orderedPlayers;
@@ -1,4 +1,4 @@
1
- import { MusicStyleType } from '../../../../../helpers/musicStyles';
1
+ import { InstrumentId } from '../../../../../helpers/instruments';
2
2
  import { LanguagesTypes } from '../../../../../lang';
3
3
  import { FileSectionId } from './types';
4
4
  export default class GroupRepertoryFileSection {
@@ -6,5 +6,5 @@ export default class GroupRepertoryFileSection {
6
6
  private lang;
7
7
  constructor(id: FileSectionId, lang?: LanguagesTypes);
8
8
  get name(): string;
9
- getOrder(musicStyle: MusicStyleType): number;
9
+ getOrder(instrumentsIds: InstrumentId[]): number;
10
10
  }
@@ -17,8 +17,8 @@ class GroupRepertoryFileSection {
17
17
  ? (0, lang_1.getTranslation)(`sections.all`, this.lang)
18
18
  : new Instrument_1.default(this.id, this.lang).name) || this.id);
19
19
  }
20
- getOrder(musicStyle) {
21
- return (0, orders_1.getOrderByMusicStyle)(musicStyle).indexOf(this.id) + 1 || Infinity;
20
+ getOrder(instrumentsIds) {
21
+ return (0, orders_1.getFileSectionsOrder)(instrumentsIds).indexOf(this.id) + 1 || Infinity;
22
22
  }
23
23
  }
24
24
  exports.default = GroupRepertoryFileSection;
@@ -30,9 +30,10 @@ export default class GroupRepertory extends Theme<GroupRepertoryData> {
30
30
  /** @deprecated use sections */
31
31
  get mainFilePath(): string | null;
32
32
  get visibility(): GroupRepertoireVisibility;
33
- get votes(): Record<string, number>;
33
+ get votes(): Record<string, import("./types").VoteValue>;
34
34
  get votesCount(): number;
35
- voteByUserId(userId: string): number | null;
35
+ get votesCountByValues(): Record<"love" | "like" | "neutral" | "dislike", number>;
36
+ voteByUserId(userId: string): import("./types").VoteValue;
36
37
  get rating(): number;
37
38
  get events(): string[];
38
39
  get eventsTL(): Record<string, import("../../Evento/types").EventTinyData>;
@@ -15,6 +15,7 @@ const tiny_1 = __importDefault(require("../../Evento/tiny"));
15
15
  const basic_1 = __importDefault(require("../../Repertory/basic"));
16
16
  const types_1 = require("./File/Section/types");
17
17
  const types_2 = require("./types");
18
+ const rates_1 = require("../../../helpers/rates");
18
19
  class GroupRepertory extends basic_1.default {
19
20
  constructor(doc, lang = lang_1.defaultLocale) {
20
21
  super(doc);
@@ -65,14 +66,17 @@ class GroupRepertory extends basic_1.default {
65
66
  get votesCount() {
66
67
  return Object.keys(this.votes).length;
67
68
  }
69
+ get votesCountByValues() {
70
+ const existingCounts = (0, lodash_1.countBy)(Object.values(this.votes));
71
+ const allCountsEntries = rates_1.rateSteps.map(({ id, value }) => [id, existingCounts[`${value}`] || 0]);
72
+ return Object.fromEntries(allCountsEntries);
73
+ }
68
74
  voteByUserId(userId) {
69
75
  return this.votes[userId] || null;
70
76
  }
71
77
  get rating() {
72
- const totalVotes = Object.entries(this.votes).reduce((acc, [, value]) => acc + value, 0);
73
- if (this.votesCount === 0 || totalVotes === 0)
74
- return 0;
75
- return Math.round((totalVotes / this.votesCount) * 100) / 100;
78
+ const totalVotes = (0, lodash_1.sum)(Object.values(this.votes));
79
+ return totalVotes == 0 ? 0 : Math.round((totalVotes / this.votesCount) * 100) / 100;
76
80
  }
77
81
  get events() {
78
82
  return this.data.events || [];
@@ -55,6 +55,7 @@ export interface GroupRepertoireFilePathItem {
55
55
  path: string;
56
56
  tag: string;
57
57
  }
58
+ export type VoteValue = 1 | 2 | 3 | 4;
58
59
  export interface GroupRepertoryData extends ThemeBasicData {
59
60
  events: string[];
60
61
  eventsTL: Record<string, EventTinyData>;
@@ -71,7 +72,7 @@ export interface GroupRepertoryData extends ThemeBasicData {
71
72
  identifyAt: Timestamp | null;
72
73
  files: Record<FileId, GroupRepertoireFile>;
73
74
  filesPath: Partial<Record<FileSectionId, GroupRepertoireFilePathItem[]>>;
74
- votes: Record<string, number>;
75
+ votes: Record<string, VoteValue>;
75
76
  thumbnailURL: string | null;
76
77
  editedAt: Timestamp | null;
77
78
  visibility: GroupRepertoireVisibility;
@@ -7,12 +7,12 @@ const date_fns_1 = require("date-fns");
7
7
  const lodash_1 = require("lodash");
8
8
  const collections_1 = require("../../helpers/collections");
9
9
  const glissandooAdmin_1 = require("../../helpers/glissandooAdmin");
10
- const orders_1 = require("../../helpers/musicStyles/orders");
11
10
  const objects_1 = require("../../helpers/objects");
12
11
  const plans_1 = require("../../helpers/plans");
13
12
  const lang_1 = require("../../lang");
14
13
  const basic_1 = __importDefault(require("./basic"));
15
14
  const types_1 = require("./types");
15
+ const orders_1 = require("../../helpers/instruments/orders");
16
16
  class Group extends basic_1.default {
17
17
  constructor(doc, lang = lang_1.defaultLocale) {
18
18
  super(doc, lang);
@@ -97,7 +97,7 @@ class Group extends basic_1.default {
97
97
  ...this.players[playerId],
98
98
  id: playerId,
99
99
  }));
100
- return (0, orders_1.orderByMusicStyle)(players, 'mainInstrument', this.musicStyle);
100
+ return (0, orders_1.orderByInstruments)(players, 'mainInstrument', this.instrumentsIds);
101
101
  }
102
102
  get isActive() {
103
103
  return this.exists && !this.deletedAt;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glissandoo/lib",
3
- "version": "1.78.0",
3
+ "version": "1.80.0",
4
4
  "description": "Glissandoo library js",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",