first version of import GUI
This commit is contained in:
parent
08b81d5ff4
commit
76f85aa538
@ -5,6 +5,11 @@ const config = require('config')
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
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')
|
require('../models/db')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -54,8 +59,8 @@ module.exports = {
|
|||||||
let artifacts = JSON.parse(fs.readFileSync(importDir+'/'+space._id+'_artifacts.json'))
|
let artifacts = JSON.parse(fs.readFileSync(importDir+'/'+space._id+'_artifacts.json'))
|
||||||
console.log('[import] space',space._id,'artifacts:',artifacts.length)
|
console.log('[import] space',space._id,'artifacts:',artifacts.length)
|
||||||
|
|
||||||
let q = {_id: space._id}
|
//let q = {where: {_id: space._id}}
|
||||||
space.creator = user._id
|
space.creator_id = user._id
|
||||||
delete space.__v
|
delete space.__v
|
||||||
|
|
||||||
// transplant homefolder
|
// transplant homefolder
|
||||||
@ -64,18 +69,36 @@ module.exports = {
|
|||||||
space.parent_space_id = user.home_folder_id
|
space.parent_space_id = user.home_folder_id
|
||||||
}
|
}
|
||||||
|
|
||||||
Space.findOneAndUpdate(q, space, {upsert: true}, function(err,res) {
|
// move nested attrs
|
||||||
if (err) console.log("[import] space upsert err:",err)
|
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++) {
|
for (var j=0; j<artifacts.length; j++) {
|
||||||
let a = artifacts[j]
|
let a = artifacts[j]
|
||||||
|
|
||||||
let q = {_id: a._id}
|
let q = {_id: a._id}
|
||||||
a.creator = user._id
|
a.user_id = user._id
|
||||||
delete a.__v
|
delete a.__v
|
||||||
delete a.payload_thumbnail_big_uri
|
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/"
|
let prefix = "/storage/"+relativeImportDir+"/"+space._id+"_files/"
|
||||||
if (a.thumbnail_uri && a.thumbnail_uri[0]!='/') a.thumbnail_uri = prefix + a.thumbnail_uri
|
if (a.thumbnail_uri && a.thumbnail_uri[0]!='/') a.thumbnail_uri = prefix + a.thumbnail_uri
|
||||||
if (a.payload_uri && a.payload_uri[0]!='/') a.payload_uri = prefix + a.payload_uri
|
if (a.payload_uri && a.payload_uri[0]!='/') a.payload_uri = prefix + a.payload_uri
|
||||||
@ -92,8 +115,10 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Artifact.findOneAndUpdate(q, a, {upsert: true}, function(err,res) {
|
db.packArtifact(a)
|
||||||
if (err) console.log("[import] artifact upsert err:",err)
|
|
||||||
|
db.Artifact.create(a).error(function(err) {
|
||||||
|
console.error("[import] artifact upsert err:",err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,6 +304,9 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
unpackArtifact: (a) => {
|
unpackArtifact: (a) => {
|
||||||
|
if (a.tags) {
|
||||||
|
a.tags = JSON.parse(a.tags);
|
||||||
|
}
|
||||||
if (a.control_points) {
|
if (a.control_points) {
|
||||||
a.control_points = JSON.parse(a.control_points);
|
a.control_points = JSON.parse(a.control_points);
|
||||||
}
|
}
|
||||||
@ -314,6 +317,9 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
packArtifact: (a) => {
|
packArtifact: (a) => {
|
||||||
|
if (a.tags) {
|
||||||
|
a.tags = JSON.stringify(a.tags);
|
||||||
|
}
|
||||||
if (a.control_points) {
|
if (a.control_points) {
|
||||||
a.control_points = JSON.stringify(a.control_points);
|
a.control_points = JSON.stringify(a.control_points);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,15 @@ function load_spaces(id, is_home, on_success, on_error) {
|
|||||||
}, 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);
|
load_resource("get", "/spaces?writablefolders=true", null, on_success, on_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,13 +8,20 @@ SpacedeckAccount = {
|
|||||||
account_confirmed_sent: false,
|
account_confirmed_sent: false,
|
||||||
account_tab: 'invoices',
|
account_tab: 'invoices',
|
||||||
password_change_error: null,
|
password_change_error: null,
|
||||||
feedback_text: ""
|
feedback_text: "",
|
||||||
|
importables: [], // spacedeck.com zip import files
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
show_account: function(user) {
|
show_account: function() {
|
||||||
this.activate_dropdown('account');
|
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) {
|
account_save_user_digest: function(val) {
|
||||||
this.user.prefs_email_digest = val;
|
this.user.prefs_email_digest = val;
|
||||||
this.save_user(function() {
|
this.save_user(function() {
|
||||||
|
@ -15,7 +15,8 @@ SpacedeckUsers = {
|
|||||||
account_remove_error: null,
|
account_remove_error: null,
|
||||||
loading_user: false,
|
loading_user: false,
|
||||||
password_reset_confirm_error: "",
|
password_reset_confirm_error: "",
|
||||||
password_reset_error: ""
|
password_reset_error: "",
|
||||||
|
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
load_user: function(on_success, on_error) {
|
load_user: function(on_success, on_error) {
|
||||||
@ -29,6 +30,12 @@ SpacedeckUsers = {
|
|||||||
if (on_success) {
|
if (on_success) {
|
||||||
on_success(user);
|
on_success(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// see spacedeck_account.js
|
||||||
|
load_importables(this.user, function(files) {
|
||||||
|
this.importables = files;
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
}.bind(this), function() {
|
}.bind(this), function() {
|
||||||
// error
|
// error
|
||||||
this.loading_user = false;
|
this.loading_user = false;
|
||||||
@ -40,18 +47,6 @@ SpacedeckUsers = {
|
|||||||
}.bind(this));
|
}.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) {
|
finalize_login: function(session_token, on_success) {
|
||||||
if(!window.socket_auth || window.socket_auth == '' || window.socket_auth == 'null') {
|
if(!window.socket_auth || window.socket_auth == '' || window.socket_auth == 'null') {
|
||||||
window.socket_auth = session_token;
|
window.socket_auth = session_token;
|
||||||
@ -169,7 +164,6 @@ SpacedeckUsers = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
password_reset_submit: function(evt, email) {
|
password_reset_submit: function(evt, email) {
|
||||||
|
|
||||||
if (evt) {
|
if (evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
@ -203,7 +197,6 @@ SpacedeckUsers = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
password_reset_confirm: function(evt, password, password_confirmation) {
|
password_reset_confirm: function(evt, password, password_confirmation) {
|
||||||
|
|
||||||
if (evt) {
|
if (evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
|
@ -21,6 +21,7 @@ var URL = require('url').URL;
|
|||||||
|
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
|
var glob = require('glob');
|
||||||
|
|
||||||
router.get('/current', function(req, res, next) {
|
router.get('/current', function(req, res, next) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
@ -306,6 +307,12 @@ router.post('/:user_id/confirm', function(req, res, next) {
|
|||||||
res.sendStatus(201);
|
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) {
|
router.get('/:user_id/import', function(req, res, next) {
|
||||||
if (req.query.zip) {
|
if (req.query.zip) {
|
||||||
res.send("importing");
|
res.send("importing");
|
||||||
|
@ -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>
|
<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-tabs" style="margin:auto">
|
||||||
<div class="dialog-tab" v-bind:class="{open:account=='profile'}" v-on:click="account='profile'"><span>[[__("profile_caption")]]</span></div>
|
<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>
|
<span class="icon icon-check"></span> <span>[[__("confirmation_sent_another")]]</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user