diff --git a/helpers/importer.js b/helpers/importer.js index 2277787..40ebcd0 100644 --- a/helpers/importer.js +++ b/helpers/importer.js @@ -5,6 +5,11 @@ const config = require('config') const fs = require('fs') const path = require('path') +const db = require('../models/db') +const Sequelize = require('sequelize') +const Op = Sequelize.Op +const uuidv4 = require('uuid/v4') + require('../models/db') module.exports = { @@ -54,8 +59,8 @@ module.exports = { let artifacts = JSON.parse(fs.readFileSync(importDir+'/'+space._id+'_artifacts.json')) console.log('[import] space',space._id,'artifacts:',artifacts.length) - let q = {_id: space._id} - space.creator = user._id + //let q = {where: {_id: space._id}} + space.creator_id = user._id delete space.__v // transplant homefolder @@ -64,17 +69,35 @@ module.exports = { space.parent_space_id = user.home_folder_id } - Space.findOneAndUpdate(q, space, {upsert: true}, function(err,res) { - if (err) console.log("[import] space upsert err:",err) - }) + // move nested attrs + console.log(space) + for (let [k,v] of Object.entries(space.advanced)) { + space[k] = v + } + + db.Space.create(space) + .error((err) => { + console.error("[import] space upsert err:",err) + }) for (var j=0; j { + if (a.tags) { + a.tags = JSON.parse(a.tags); + } if (a.control_points) { a.control_points = JSON.parse(a.control_points); } @@ -314,6 +317,9 @@ module.exports = { }, packArtifact: (a) => { + if (a.tags) { + a.tags = JSON.stringify(a.tags); + } if (a.control_points) { a.control_points = JSON.stringify(a.control_points); } diff --git a/public/javascripts/backend.js b/public/javascripts/backend.js index 9b7bb08..5739fea 100644 --- a/public/javascripts/backend.js +++ b/public/javascripts/backend.js @@ -133,7 +133,15 @@ function load_spaces(id, is_home, on_success, on_error) { }, on_error); } -function load_writable_folders( on_success, on_error) { +function load_importables(user, on_success, on_error) { + load_resource("get", "/users/"+user._id+"/importables", null, on_success, on_error); +} + +function import_zip(user, filename, on_success, on_error) { + load_resource("get", "/users/"+user._id+"/import?zip="+filename, null, on_success, on_error); +} + +function load_writable_folders(on_success, on_error) { load_resource("get", "/spaces?writablefolders=true", null, on_success, on_error); } diff --git a/public/javascripts/spacedeck_account.js b/public/javascripts/spacedeck_account.js index 1c0b5d1..06f6846 100644 --- a/public/javascripts/spacedeck_account.js +++ b/public/javascripts/spacedeck_account.js @@ -8,13 +8,20 @@ SpacedeckAccount = { account_confirmed_sent: false, account_tab: 'invoices', password_change_error: null, - feedback_text: "" + feedback_text: "", + importables: [], // spacedeck.com zip import files }, methods: { - show_account: function(user) { + show_account: function() { this.activate_dropdown('account'); }, + start_zip_import: function(f) { + if (confirm("Your archive will be imported in the background. This can take a few minutes. You can continue using Spacedeck in the meantime.")) { + import_zip(this.user, f); + } + }, + account_save_user_digest: function(val) { this.user.prefs_email_digest = val; this.save_user(function() { diff --git a/public/javascripts/spacedeck_users.js b/public/javascripts/spacedeck_users.js index 59a66d2..4cbd60d 100644 --- a/public/javascripts/spacedeck_users.js +++ b/public/javascripts/spacedeck_users.js @@ -15,7 +15,8 @@ SpacedeckUsers = { account_remove_error: null, loading_user: false, password_reset_confirm_error: "", - password_reset_error: "" + password_reset_error: "", + }, methods:{ load_user: function(on_success, on_error) { @@ -29,6 +30,12 @@ SpacedeckUsers = { if (on_success) { on_success(user); } + + // see spacedeck_account.js + load_importables(this.user, function(files) { + this.importables = files; + }.bind(this)); + }.bind(this), function() { // error this.loading_user = false; @@ -40,18 +47,6 @@ SpacedeckUsers = { }.bind(this)); }, - login_google: function(evt) { - this.loading_user = true; - - create_oauthtoken(function(data){ - this.loading_user = false; - location.href = data.url; - }, function(xhr){ - this.loading_user = false; - alert("could not get oauth token"); - }); - }, - finalize_login: function(session_token, on_success) { if(!window.socket_auth || window.socket_auth == '' || window.socket_auth == 'null') { window.socket_auth = session_token; @@ -169,7 +164,6 @@ SpacedeckUsers = { }, password_reset_submit: function(evt, email) { - if (evt) { evt.preventDefault(); evt.stopPropagation(); @@ -203,7 +197,6 @@ SpacedeckUsers = { }, password_reset_confirm: function(evt, password, password_confirmation) { - if (evt) { evt.preventDefault(); evt.stopPropagation(); diff --git a/routes/api/users.js b/routes/api/users.js index d7ad410..f389bf9 100644 --- a/routes/api/users.js +++ b/routes/api/users.js @@ -21,6 +21,7 @@ var URL = require('url').URL; var express = require('express'); var router = express.Router(); +var glob = require('glob'); router.get('/current', function(req, res, next) { if (req.user) { @@ -306,6 +307,12 @@ router.post('/:user_id/confirm', function(req, res, next) { res.sendStatus(201); }); +router.get('/:user_id/importables', function(req, res, next) { + glob('*.zip', function(err, files) { + res.status(200).json(files); + }); +}); + router.get('/:user_id/import', function(req, res, next) { if (req.query.zip) { res.send("importing"); diff --git a/views/partials/account.html b/views/partials/account.html index 5c20254..7aeaf81 100644 --- a/views/partials/account.html +++ b/views/partials/account.html @@ -1,6 +1,6 @@
- +
[[__("profile_caption")]]
@@ -80,6 +80,14 @@ [[__("confirmation_sent_another")]]

+ +
+ +

No .ZIP files found in Spacedeck application folder.

+
    +
  • {{f}}
  • +
+