Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes duplicated import/export feature #270

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions app/ui/managers/inventory_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
28 changes: 0 additions & 28 deletions app/ui/views2/collection/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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\']',
Expand All @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
56 changes: 0 additions & 56 deletions app/ui/views2/collection/copy_decks_export_to_clipboard_dialog.js

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions app/ui/views2/collection/templates/collection.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@
</div>
<button class="btn btn-clean btn-clean-primary crafting-mode-start">{{localize 'collection.crafting_button_label'}} <i class="fa fa-wrench"></i></button>
<button class="btn btn-clean btn-clean-primary crafting-mode-stop">{{localize 'collection.back_button_label'}} <i class="fa fa-reply"></i></button>
<button class="btn btn-clean btn-clean-primary export-decks">Export Decks</button>
<button class="btn btn-clean btn-clean-primary import-decks">Import Decks</button>
<div class="next-page">
<div class="btn btn-clean"></div>
</div>
Expand Down

This file was deleted.

This file was deleted.

49 changes: 0 additions & 49 deletions server/lib/data_access/decks.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
###*
Expand Down Expand Up @@ -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
25 changes: 0 additions & 25 deletions server/routes/api/me/decks.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down