first version of import GUI

This commit is contained in:
Lukas F. Hartmann 2018-04-12 17:41:22 +02:00
parent 08b81d5ff4
commit 76f85aa538
7 changed files with 81 additions and 27 deletions

View File

@ -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<artifacts.length; j++) {
let a = artifacts[j]
let q = {_id: a._id}
a.creator = user._id
a.user_id = user._id
delete a.__v
delete a.payload_thumbnail_big_uri
// move nested attrs
for (let [k,v] of Object.entries(a.meta)) {
a[k] = v
}
for (let [k,v] of Object.entries(a.board)) {
a[k] = v
}
for (let [k,v] of Object.entries(a.style)) {
a[k] = v
}
let prefix = "/storage/"+relativeImportDir+"/"+space._id+"_files/"
if (a.thumbnail_uri && a.thumbnail_uri[0]!='/') a.thumbnail_uri = prefix + a.thumbnail_uri
@ -92,8 +115,10 @@ module.exports = {
}
}
Artifact.findOneAndUpdate(q, a, {upsert: true}, function(err,res) {
if (err) console.log("[import] artifact upsert err:",err)
db.packArtifact(a)
db.Artifact.create(a).error(function(err) {
console.error("[import] artifact upsert err:",err)
})
}
}

View File

@ -304,6 +304,9 @@ module.exports = {
},
unpackArtifact: (a) => {
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);
}

View File

@ -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);
}

View File

@ -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() {

View File

@ -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();

View File

@ -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");

View File

@ -1,6 +1,6 @@
<div id="team" class="dialog in" style="padding:100px;z-index:20000;position:absolute;width:100%;min-height:100%;background-color:#eee" v-if="active_view == 'account' && user" v-cloak>
<a href="/spaces" class="btn btn-round btn-icon btn-stroke-darken btn-md pull-right" style="position:absolute;top:30px;right:30px"><span class="icon icon-cross-0"></span></a>
<a href="/spaces" class="btn btn-round btn-icon btn-dark btn-md pull-right" style="position:absolute;top:30px;right:30px"><span class="icon icon-cross-0"></span></a>
<div class="dialog-tabs" style="margin:auto">
<div class="dialog-tab" v-bind:class="{open:account=='profile'}" v-on:click="account='profile'"><span>[[__("profile_caption")]]</span></div>
@ -80,6 +80,14 @@
<span class="icon icon-check"></span> <span>[[__("confirmation_sent_another")]]</span>
</p>
</div>
<div class="form-group">
<label class="label">Spacedeck.com Data Import</label>
<p v-if="!importables">No .ZIP files found in Spacedeck application folder.</p>
<ul>
<li v-for="f in importables">{{f}} <button v-on:click="start_zip_import(f)">Start Import</button></li>
</ul>
</div>
</div>
</div>