From b4b537a65ef6f8863532ff5a37d450bac996a216 Mon Sep 17 00:00:00 2001 From: Sriram Viswanathan Date: Mon, 28 Nov 2022 21:28:22 -0500 Subject: [PATCH 1/3] Update book as primary sort and select sort as secondary --- rest/app/pp/serializers.py | 13 +++- .../CharacterGroupingDetail.vue | 45 +++++++---- .../Interfaces/CharacterGroupingInterface.vue | 75 ++++++++++++++----- 3 files changed, 96 insertions(+), 37 deletions(-) diff --git a/rest/app/pp/serializers.py b/rest/app/pp/serializers.py index c73d2fa..d4b3b1f 100644 --- a/rest/app/pp/serializers.py +++ b/rest/app/pp/serializers.py @@ -40,7 +40,17 @@ class Meta: fields = ["url", "id", "label", "sequence", "image"] +class BookNameSerializer(serializers.ModelSerializer): + class Meta: + model = models.Book + fields = [ + "id", + "label", + ] + + class CharacterFlatSerializer(serializers.ModelSerializer): + book = BookNameSerializer(many=False) character_class = serializers.PrimaryKeyRelatedField( queryset=models.CharacterClass.objects.all() ) @@ -67,7 +77,8 @@ class Meta: "exposure", "offset", "image", - "created_by_run_id" + "created_by_run_id", + "book", ] diff --git a/vue/src/components/CharacterGroups/CharacterGroupingDetail.vue b/vue/src/components/CharacterGroups/CharacterGroupingDetail.vue index 3b71936..4ffa66d 100644 --- a/vue/src/components/CharacterGroups/CharacterGroupingDetail.vue +++ b/vue/src/components/CharacterGroups/CharacterGroupingDetail.vue @@ -157,6 +157,7 @@ export default { cg_id: null, order: 'character_class', selectedCharacters: {}, + ordered_characters: [], selectedCharCount: 0, showCreate: false, image_size: 'actual', @@ -166,20 +167,6 @@ export default { edit_mode() { return !!this.$route.query.edit }, - ordered_characters() { - // order default by run - associated with a book - const orderBy = ['created_by_run_id'] - const direction = ['asc'] - if (this.order.variable !== 'bookseq,pageseq,lineseq,sequence') { - orderBy.push(this.lodash_order.variable) - direction.push(this.lodash_order.direction) - } - return _.orderBy( - this.character_group.characters, - [this.lodash_order.variable], - [this.lodash_order.direction] - ) - }, lodash_order() { var direction = 'asc' if (this.order.includes('-')) { @@ -205,6 +192,23 @@ export default { }, }, methods: { + order_characters() { + if (this.lodash_order.variable === 'bookseq,pageseq,lineseq,sequence') { + return this.character_group.characters + } else { + const defaultOrderByBook = [ + (character) => + character.book.label.substring( + character.book.label.indexOf(' ') + 1 + ), + ] + return _.orderBy( + this.character_group.characters, + [...defaultOrderByBook, this.lodash_order.variable], + ['asc', this.lodash_order.direction] + ) + } + }, display_date: function (date) { return moment(new Date(date)).format('MM-DD-YY, h:mm a') }, @@ -310,8 +314,17 @@ export default { ) }, }, - created: function () { - // this.get_book(this.id); + watch: { + // everytime order changes, re-order the characters + order: function () { + this.ordered_characters = this.order_characters() + }, + character_group: function (val) { + // first time initialization on load + if (val) { + this.ordered_characters = this.order_characters() + } + }, }, } diff --git a/vue/src/components/Interfaces/CharacterGroupingInterface.vue b/vue/src/components/Interfaces/CharacterGroupingInterface.vue index 9eab383..35b2d4a 100644 --- a/vue/src/components/Interfaces/CharacterGroupingInterface.vue +++ b/vue/src/components/Interfaces/CharacterGroupingInterface.vue @@ -31,21 +31,31 @@
-
-
- {{ new_cg_card.button_text[new_cg_card.show] }} - - -
- +
+
+
+
+ {{ new_cg_card.button_text[new_cg_card.show] }} + + +
+ +
+
+ +
+
@@ -156,6 +166,7 @@ diff --git a/vue/src/components/Interfaces/CharacterGroupingInterface.vue b/vue/src/components/Interfaces/CharacterGroupingInterface.vue index 35b2d4a..9eab383 100644 --- a/vue/src/components/Interfaces/CharacterGroupingInterface.vue +++ b/vue/src/components/Interfaces/CharacterGroupingInterface.vue @@ -31,31 +31,21 @@
-
-
-
-
- {{ new_cg_card.button_text[new_cg_card.show] }} - - -
- -
-
- -
-
+
+
+ {{ new_cg_card.button_text[new_cg_card.show] }} + + +
+
@@ -166,7 +156,6 @@