Skip to content

Commit

Permalink
Merge pull request #175 from buttercup-pw/march-14-fixes
Browse files Browse the repository at this point in the history
Tree Fixes
  • Loading branch information
sallar authored Mar 15, 2017
2 parents 0536a59 + 5c63fde commit 104b2ae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
10 changes: 5 additions & 5 deletions src/renderer/system/buttercup/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Archive
} from 'buttercup-web';

let __curentWorkspace = null;
let __currentWorkspace = null;

/**
* Read text file from disk
Expand Down Expand Up @@ -66,7 +66,7 @@ function createWorkspace(content, password) {
export function loadWorkspace(filename, password) {
const content = readTextFile(filename);
return createWorkspace(content, password).then(workspace => {
__curentWorkspace = {
__currentWorkspace = {
instance: workspace,
filename
};
Expand Down Expand Up @@ -94,7 +94,7 @@ export function newWorkspace(filename, password) {
.then(content => {
writeTextFile(filename, content);
return createWorkspace(content, password).then(workspace => {
__curentWorkspace = {
__currentWorkspace = {
instance: workspace,
filename
};
Expand All @@ -106,10 +106,10 @@ export function newWorkspace(filename, password) {
}

export function getWorkspace() {
if (__curentWorkspace === null) {
if (__currentWorkspace === null) {
return null;
}
return __curentWorkspace;
return __currentWorkspace;
}

export function getArchive() {
Expand Down
30 changes: 17 additions & 13 deletions src/renderer/system/buttercup/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,17 @@ export function saveGroup(groupId, title) {
export function moveGroup(groupId, parentId, dropToGap = false) {
const arch = getArchive();
const group = arch.findGroupByID(groupId);
const parent = parentId ? arch.findGroupByID(parentId) : arch;
let parent = parentId ? arch.findGroupByID(parentId) : arch;

if (!group || !parent) {
throw new Error('Group has not been found.');
if (dropToGap) {
parent = findParentGroup(parentId, arch);
}

if (dropToGap && isRootGroup(parent)) {
group.moveTo(arch);
} else {
group.moveToGroup(parent);
if (!group || !parent) {
throw new Error('Group has not been found.');
}

group.moveToGroup(parent);
save();
}

Expand All @@ -119,14 +118,19 @@ export function emptyTrash() {
}

/**
* Check if a Group is a Root Group
* Find a Group's parent Group
* @param {String} groupId Group ID to comapre
* @param {Buttercup.Group} group Group Object
*/
function isRootGroup(group) {
const rootGroups = getArchive().getGroups();
for (let i = 0; i < rootGroups.length; i += 1) {
if (group.getID() === rootGroups[i].getID()) {
return true;
function findParentGroup(groupId, group) {
const groups = group.getGroups();
for (const subGroup of groups) {
if (subGroup.getID() === groupId) {
return group;
}
const findInChildren = findParentGroup(groupId, subGroup);
if (findInChildren !== false) {
return findInChildren;
}
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/system/buttercup/import.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Archive } from 'buttercup-web';
import { showPasswordDialog } from '../dialog';
import { getArchive, saveWorkspace } from './archive';
import { Archive } from "buttercup-web";

export function importHistoryFromRequest(request) {
const { history } = request;
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1727,11 +1727,11 @@ buttercup-generator@^0.0.2:
mngen "^1.0.0"
password-generator "^2.1.0"

buttercup-importer@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/buttercup-importer/-/buttercup-importer-0.6.1.tgz#c866f60431d3e1d00e6d2fc2a34389ed5c034fbc"
buttercup-importer@~0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/buttercup-importer/-/buttercup-importer-0.7.0.tgz#64126d7a5588d0af0008497e9f6795df09869bcd"
dependencies:
buttercup "~0.33.0"
buttercup "~0.35.0"
kdbxweb "~0.2.1"
xml2js "~0.4.13"

Expand All @@ -1748,20 +1748,20 @@ buttercup-ui@^0.3.1:
styled-components "^1.4.3"
zxcvbn "^4.4.2"

buttercup-web@~0.17.2:
version "0.17.3"
resolved "https://registry.yarnpkg.com/buttercup-web/-/buttercup-web-0.17.3.tgz#4be8294b90fefa00b7e1cf1b13914f8754be7b61"
buttercup-web@~0.23.0:
version "0.23.0"
resolved "https://registry.yarnpkg.com/buttercup-web/-/buttercup-web-0.23.0.tgz#27832be11b3dc81a0442dbbfa90093d19c9df9d6"
dependencies:
buttercup "~0.33.2"
buttercup "~0.35.0"

buttercup@~0.33.0, buttercup@~0.33.2:
version "0.33.2"
resolved "https://registry.yarnpkg.com/buttercup/-/buttercup-0.33.2.tgz#2b9dab2a7c68f4520f91eb1a32789cff5364ffeb"
buttercup@~0.35.0:
version "0.35.0"
resolved "https://registry.yarnpkg.com/buttercup/-/buttercup-0.35.0.tgz#eecdc4f9d82497052f049b36c03470ac7afa3cbf"
dependencies:
clone "~1.0.2"
debug "^2.3.3"
gzip-js "~0.3.2"
iocane "~0.5.0"
iocane "~0.6.0"
node-fetch "~1.6.3"
uuid "~2.0.1"
webdav-fs "~0.4.0"
Expand Down Expand Up @@ -4307,9 +4307,9 @@ invert-kv@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6"

iocane@~0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/iocane/-/iocane-0.5.0.tgz#221e74b70eb393957031851293e9846a9c1a292a"
iocane@~0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/iocane/-/iocane-0.6.0.tgz#4e77cc7cb6f40c674ccf5bc40e0d8c73bd93cb22"
dependencies:
debug "^2.3.2"
hash_file "^0.1.1"
Expand Down

0 comments on commit 104b2ae

Please sign in to comment.