From 7ea9d0fec2cf4f67c8a3696a7a8d16601902493c Mon Sep 17 00:00:00 2001 From: Will Roberts Date: Wed, 18 Jan 2023 11:56:58 -0500 Subject: [PATCH] Removes duplicated import/export feature --- app/ui/managers/inventory_manager.js | 40 ----------- app/ui/views2/collection/collection.js | 28 -------- .../copy_decks_export_to_clipboard_dialog.js | 56 --------------- ...aste_decks_import_from_clipboard_dialog.js | 71 ------------------- .../collection/templates/collection.hbs | 2 - .../copy_decks_export_to_clipboard_dialog.hbs | 17 ----- ...ste_decks_import_from_clipboard_dialog.hbs | 20 ------ server/lib/data_access/decks.coffee | 49 ------------- server/routes/api/me/decks.coffee | 25 ------- 9 files changed, 308 deletions(-) delete mode 100644 app/ui/views2/collection/copy_decks_export_to_clipboard_dialog.js delete mode 100644 app/ui/views2/collection/paste_decks_import_from_clipboard_dialog.js delete mode 100644 app/ui/views2/collection/templates/copy_decks_export_to_clipboard_dialog.hbs delete mode 100644 app/ui/views2/collection/templates/paste_decks_import_from_clipboard_dialog.hbs diff --git a/app/ui/managers/inventory_manager.js b/app/ui/managers/inventory_manager.js index b9083b2ec..bade8b3ad 100644 --- a/app/ui/managers/inventory_manager.js +++ b/app/ui/managers/inventory_manager.js @@ -682,46 +682,6 @@ var InventoryManager = Manager.extend({ }.bind(this)); }, - exportDecks: function () { - return new Promise(function (resolve, reject) { - var request = $.ajax({ - url: process.env.API_URL + '/api/me/decks/export-decks', - type: 'GET', - contentType: 'application/json', - }); - - request.done(function (response) { - resolve(response); - }); - - request.fail(function (response) { - var errorMessage = response.responseJSON ? response.responseJSON.message : 'Failed to export decks.'; - reject(errorMessage); - }); - }.bind(this)); - }, - - importDecks: function (input) { - return new Promise(function (resolve, reject) { - var request = $.ajax({ - url: process.env.API_URL + '/api/me/decks/import-decks', - type: 'PUT', - contentType: 'application/json', - dataType: 'json', - data: input, - }); - - request.done(function (response) { - resolve(response); - }); - - request.fail(function (response) { - var errorMessage = response.responseJSON ? response.responseJSON.error : 'Failed to import decks.'; - reject(errorMessage); - }); - }.bind(this)); - }, - /* endregion ACTIONS */ /* region GETTERS / SETTERS */ diff --git a/app/ui/views2/collection/collection.js b/app/ui/views2/collection/collection.js index f4129822d..617123d3c 100644 --- a/app/ui/views2/collection/collection.js +++ b/app/ui/views2/collection/collection.js @@ -25,8 +25,6 @@ var GamesManager = require('app/ui/managers/games_manager'); var ConfirmDialogItemView = require('app/ui/views/item/confirm_dialog'); var ErrorDialogItemView = require('app/ui/views/item/error_dialog'); var ActivityDialogItemView = require('app/ui/views/item/activity_dialog'); -var CopyDecksDialogView = require('app/ui/views2/collection/copy_decks_export_to_clipboard_dialog'); -var PasteDecksDialogView = require('app/ui/views2/collection/paste_decks_import_from_clipboard_dialog'); var moment = require('moment'); var i18next = require('i18next'); var CollectionTmpl = require('./templates/collection.hbs'); @@ -59,8 +57,6 @@ var CollectionLayout = Backbone.Marionette.LayoutView.extend({ $cardsList: '.collection-cards .cards-list', $startCraftingModeButton: '.crafting-mode-start', $stopCraftingModeButton: '.crafting-mode-stop', - $exportDecksButton: '.export-decks', - $importDecksButton: '.import-decks', $searchSubmit: '.search-submit', $searchClear: '.search-clear', $searchInput: '.search input[type=\'search\']', @@ -82,8 +78,6 @@ var CollectionLayout = Backbone.Marionette.LayoutView.extend({ 'click .next-page': 'onNextPage', 'click .crafting-mode-start': 'onStartCraftingMode', 'click .crafting-mode-stop': 'onStopCraftingMode', - 'click .export-decks': 'onExportDecks', - 'click .import-decks': 'onImportDecks', 'click .browsing-mode': 'onBrowsingMode', 'click .search-clear': 'onSearchClear', 'input .search input[type=\'search\']': 'onSearch', @@ -665,24 +659,6 @@ var CollectionLayout = Backbone.Marionette.LayoutView.extend({ NavigationManager.getInstance().showLastRoute(); }, - onExportDecks: function (event) { - InventoryManager.getInstance().exportDecks() - .then((response) => { - NavigationManager.getInstance().showDialogView(new CopyDecksDialogView({ - decksExport: response, - })); - }) - .catch((error) => { - NavigationManager.getInstance().showDialogView(new ErrorDialogItemView({ - title: `Failed to export decks: ${error}`, - })); - }); - }, - - onImportDecks: function (event) { - NavigationManager.getInstance().showDialogView(new PasteDecksDialogView()); - }, - _cleanupCurrentDeck: function () { if (this._deck) { // delete current deck if it has no general @@ -710,8 +686,6 @@ var CollectionLayout = Backbone.Marionette.LayoutView.extend({ // toggle classes this.$el.removeClass('deck-building crafting deck-card-back-selecting'); this.ui.$startCraftingModeButton.removeClass('hidden disabled'); - this.ui.$exportDecksButton.removeClass('hidden disabled'); - this.ui.$importDecksButton.removeClass('hidden disabled'); this.ui.$stopCraftingModeButton.addClass('hidden disabled'); // mode flags @@ -823,8 +797,6 @@ var CollectionLayout = Backbone.Marionette.LayoutView.extend({ // toggle buttons this.ui.$startCraftingModeButton.addClass('hidden disabled'); - this.ui.$exportDecksButton.addClass('hidden disabled'); - this.ui.$importDecksButton.addClass('hidden disabled'); this.ui.$stopCraftingModeButton.removeClass('hidden disabled'); // start crafting in the collection diff --git a/app/ui/views2/collection/copy_decks_export_to_clipboard_dialog.js b/app/ui/views2/collection/copy_decks_export_to_clipboard_dialog.js deleted file mode 100644 index 242ab7683..000000000 --- a/app/ui/views2/collection/copy_decks_export_to_clipboard_dialog.js +++ /dev/null @@ -1,56 +0,0 @@ -// pragma PKGS: alwaysloaded - -'use strict'; - -var EVENTS = require('app/common/event_types'); -var RSX = require('app/data/resources'); -var NavigationManager = require('app/ui/managers/navigation_manager'); -var Animations = require('app/ui/views/animations'); -var audio_engine = require('app/audio/audio_engine'); -var Templ = require('app/ui/views2/collection/templates/copy_decks_export_to_clipboard_dialog.hbs'); -var Clipboard = require('clipboard'); - -var CopyDecksExportItemView = Backbone.Marionette.ItemView.extend({ - - id: 'app-copy-decks-export-dialog', - className: 'dialog prompt-modal', - - template: Templ, - - events: { - 'click .cancel-dialog': 'onCancel', - }, - - animateIn: Animations.fadeIn, - animateOut: Animations.fadeOut, - - initialize: function () { - this.model = new Backbone.Model({ - decksExport: JSON.stringify(this.options.decksExport) || 'Export failed', - background: this.options.background, - }); - }, - - onRender: function () { - new Clipboard('#copy_decks_export_button'); - }, - - onShow: function () { - // listen to specific user attempted actions as this is a dialog and dialogs block user actions - this.listenToOnce(NavigationManager.getInstance(), EVENTS.user_attempt_cancel, this.onCancel); - this.listenToOnce(NavigationManager.getInstance(), EVENTS.user_attempt_skip, this.onCancel); - this.listenToOnce(NavigationManager.getInstance(), EVENTS.user_attempt_confirm, this.onCancel); - - // play error audio - audio_engine.current().play_effect_for_interaction(RSX.sfx_ui_error.audio, CONFIG.ERROR_SFX_PRIORITY); - }, - - onCancel: function () { - audio_engine.current().play_effect_for_interaction(RSX.sfx_ui_cancel.audio, CONFIG.CANCEL_SFX_PRIORITY); - NavigationManager.getInstance().destroyDialogView(); - this.trigger('cancel'); - }, - -}); - -module.exports = CopyDecksExportItemView; diff --git a/app/ui/views2/collection/paste_decks_import_from_clipboard_dialog.js b/app/ui/views2/collection/paste_decks_import_from_clipboard_dialog.js deleted file mode 100644 index 8185ec834..000000000 --- a/app/ui/views2/collection/paste_decks_import_from_clipboard_dialog.js +++ /dev/null @@ -1,71 +0,0 @@ -// pragma PKGS: alwaysloaded - -'use strict'; - -var EVENTS = require('app/common/event_types'); -var RSX = require('app/data/resources'); -var InventoryManager = require('app/ui/managers/inventory_manager'); -var NavigationManager = require('app/ui/managers/navigation_manager'); -var ErrorDialogItemView = require('app/ui/views/item/error_dialog'); -var Animations = require('app/ui/views/animations'); -var audio_engine = require('app/audio/audio_engine'); -var Templ = require('app/ui/views2/collection/templates/paste_decks_import_from_clipboard_dialog.hbs'); -var Clipboard = require('clipboard'); - -var PasteDecksImportItemView = Backbone.Marionette.ItemView.extend({ - id: 'app-paste-decks-import-dialog', - className: 'dialog prompt-modal', - - template: Templ, - - events: { - 'click .cancel-dialog': 'onCancel', - 'click .import-decks-submit': 'onImportDecksSubmit', - }, - - animateIn: Animations.fadeIn, - animateOut: Animations.fadeOut, - - initialize: function () { - this.model = new Backbone.Model({ - background: this.options.background, - }); - }, - - onRender: function () { - new Clipboard('#paste_decks_import_button'); - }, - - onShow: function () { - // listen to specific user attempted actions as this is a dialog and dialogs block user actions - this.listenToOnce(NavigationManager.getInstance(), EVENTS.user_attempt_cancel, this.onCancel); - this.listenToOnce(NavigationManager.getInstance(), EVENTS.user_attempt_skip, this.onCancel); - this.listenToOnce(NavigationManager.getInstance(), EVENTS.user_attempt_confirm, this.onCancel); - - // play error audio - audio_engine.current().play_effect_for_interaction(RSX.sfx_ui_error.audio, CONFIG.ERROR_SFX_PRIORITY); - }, - - onCancel: function () { - audio_engine.current().play_effect_for_interaction(RSX.sfx_ui_cancel.audio, CONFIG.CANCEL_SFX_PRIORITY); - NavigationManager.getInstance().destroyDialogView(); - this.trigger('cancel'); - }, - - onImportDecksSubmit: function (event) { - const input = document.getElementById('input_text').value; - InventoryManager.getInstance().importDecks(input) - .then(function (response) { - // Close the dialog window. - this.onCancel(); - }.bind(this)) - .catch((error) => { - console.error('import decks error:', error); - NavigationManager.getInstance().showDialogView(new ErrorDialogItemView({ - title: `Failed to import decks: ${error}`, - })); - }); - }, -}); - -module.exports = PasteDecksImportItemView; diff --git a/app/ui/views2/collection/templates/collection.hbs b/app/ui/views2/collection/templates/collection.hbs index ff0adf4bf..ff9200166 100644 --- a/app/ui/views2/collection/templates/collection.hbs +++ b/app/ui/views2/collection/templates/collection.hbs @@ -83,8 +83,6 @@ - -
diff --git a/app/ui/views2/collection/templates/copy_decks_export_to_clipboard_dialog.hbs b/app/ui/views2/collection/templates/copy_decks_export_to_clipboard_dialog.hbs deleted file mode 100644 index 1717b7acc..000000000 --- a/app/ui/views2/collection/templates/copy_decks_export_to_clipboard_dialog.hbs +++ /dev/null @@ -1,17 +0,0 @@ -
- - diff --git a/app/ui/views2/collection/templates/paste_decks_import_from_clipboard_dialog.hbs b/app/ui/views2/collection/templates/paste_decks_import_from_clipboard_dialog.hbs deleted file mode 100644 index e20747fa1..000000000 --- a/app/ui/views2/collection/templates/paste_decks_import_from_clipboard_dialog.hbs +++ /dev/null @@ -1,20 +0,0 @@ -
- - diff --git a/server/lib/data_access/decks.coffee b/server/lib/data_access/decks.coffee index 337905bec..a059769e7 100644 --- a/server/lib/data_access/decks.coffee +++ b/server/lib/data_access/decks.coffee @@ -12,10 +12,7 @@ crypto = require('crypto') # SDK imports SDK = require '../../../app/sdk' -FactionFactory = require '../../../app/sdk/cards/factionFactory.coffee' -CardFactory = require '../../../app/sdk/cards/cardFactory.coffee' UtilsGameSession = require '../../../app/common/utils/utils_game_session.coffee' -en = require '../../../app/localization/locales/en/index.json' class DecksModule ###* @@ -146,50 +143,4 @@ class DecksModule return final - # Retrieve a user's decks, and return them as a JSON-encoded string. - @getDecksAsJSON: (userId) -> - result = {} - @decksForUser(userId) - .then (decks) -> - for deckData in decks - # Collect card names. - cardNames = [] - for card in deckData.cards - cardNames.push(en['cards'][CardFactory.cardForIdentifier(card, null).name.substring(6)]) - # Encode the results. - result[deckData.id] = - name: deckData.name - faction_id: deckData.faction_id - faction_name: FactionFactory.factionForIdentifier(deckData.faction_id).devName - cards: deckData.cards - card_names: cardNames - spell_count: deckData.spell_count - minion_count: deckData.minion_count - artifact_count: deckData.artifact_count - Logger.module("DecksModule").debug "encoded decks for user #{userId}" - return result - .catch (error) -> - Logger.module("DecksModule").error "failed to encode decks: #{error}" - throw error - - # Given a JSON object from @getDecksAsJSON, create corresponding decks for the user. - @putDecksFromJSON: (userId, obj) -> - for key in Object.keys(obj) - deck = obj[key] - @addDeck( - userId, - deck.faction_id, - deck.name, - deck.cards, - deck.spell_count, - deck.minion_count, - deck.artifact_count, - 0, - null - ).then (deck) -> - Logger.module("DecksModule").debug "created deck #{deck.id} for user #{userId}" - .catch (error) -> - Logger.module("DecksModule").error "failed to create deck: #{error}" - throw error - module.exports = DecksModule diff --git a/server/routes/api/me/decks.coffee b/server/routes/api/me/decks.coffee index ca6743d04..92c64fc02 100644 --- a/server/routes/api/me/decks.coffee +++ b/server/routes/api/me/decks.coffee @@ -21,31 +21,6 @@ router.get '/', (req, res, next) -> res.status(200).json(DataAccessHelpers.restifyData(decks)) .catch (error) -> next(error) -# Exports all user decks to JSON. -router.get '/export-decks', (req, res, next) -> - user_id = req.user.d.id - if !user_id? - return res.status(400).json({'message': 'User ID must be provided'}) - - return DecksModule.getDecksAsJSON(user_id) - .then (result) -> res.status(200).json(result) - .catch (error) -> next(error) - -# Imports user decks from JSON. -router.put '/import-decks', (req, res, next) -> - user_id = req.user.d.id - if !user_id? - return res.status(400).json({'message': 'User ID must be provided'}) - - if !req.body? - return res.status(400).json({'message': 'Data must be provided'}) - - try - DecksModule.putDecksFromJSON(user_id, req.body) - return res.status(200).json({'message': 'Imported deck(s).'}) - catch error - return next(error) - router.get '/:deck_id', (req, res, next) -> result = t.validate(req.params.deck_id, t.subtype(t.Str, (s) -> s.length <= 36)) if not result.isValid()