Skip to content

Commit

Permalink
i think saving and loading works now? with a JSON db (lol)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Murphy committed Aug 4, 2018
1 parent 542cd3e commit 459ac1d
Show file tree
Hide file tree
Showing 17 changed files with 808 additions and 415 deletions.
15 changes: 5 additions & 10 deletions client/dropdown-menu.js
Expand Up @@ -123,21 +123,16 @@ class Menu {
}

get state() {
return {
is_visible: this.is_visible,
pinned: this.pinned
};
return this.pinned;
}

set state(state) {

this.reset();
if (!state)
return;

if (state)
this.pinned = state.pinned || this.pinned;

_.each(state, (bool, name) => {
this.pinned[name] = bool;
});

}
}

Expand Down
13 changes: 12 additions & 1 deletion client/funcs.js
Expand Up @@ -67,7 +67,18 @@ module.exports = {

getPresentUsers: room => {
return Object.keys(room.users).length;
}
},

dedup: (master, slave) => {

let dedup = {};

_.each(slave, (value, key) => {
if (master[key] !== value)
dedup[key] = value;
});

return dedup;
},

};
5 changes: 2 additions & 3 deletions client/graph.js
Expand Up @@ -323,11 +323,10 @@ class Graph {
);

token.mapHeads(head => {
getDependencyEdge(format, head.token, token, head.deprel, this.progress);

progress.total += 1;
this.progress.total += 1;
if (head.deprel && head.deprel !== '_')
progress.done += 1;
this.progress.done += 1;

if (head.token.name === 'RootToken')
return;
Expand Down
30 changes: 22 additions & 8 deletions client/gui.js
Expand Up @@ -18,9 +18,7 @@ class GUI {
constructor() {

this.is_textarea_visible = true;
this.are_labels_visible = true;
this.is_vertical = false;
this.is_ltr = true;
this.is_label_bar_visible = true;
this.readonly = false;

this.pan = this.pan || null;
Expand Down Expand Up @@ -115,12 +113,13 @@ class GUI {

}

/*
get state() {
return {
menu: this.menu ? this.menu.state : null,
is_textarea_visible: this.is_textarea_visible,
are_labels_visible: this.are_labels_visible,
is_label_bar_visible: this.is_label_bar_visible,
is_vertical: this.is_vertical,
is_ltr: this.is_ltr,
readonly: this.readonly,
Expand All @@ -136,7 +135,7 @@ class GUI {
this.menu.state = state.menu;
this.is_textarea_visible = state.is_textarea_visible,
this.are_labels_visible = state.are_labels_visible,
this.is_label_bar_visible = state.is_label_bar_visible,
this.is_vertical = state.is_vertical;
this.is_ltr = state.is_ltr;
this.readonly = state.readonly;
Expand All @@ -146,6 +145,7 @@ class GUI {
this.update();
}
*/

update() {
if (!this.inBrowser)
Expand Down Expand Up @@ -232,7 +232,7 @@ class GUI {
}

$('#label-container')
.css('display', this.are_labels_visible && this.is_textarea_visible
.css('display', this.is_label_bar_visible && this.is_textarea_visible
? 'flex'
: 'none');

Expand Down Expand Up @@ -306,7 +306,7 @@ class GUI {
if ($(e.target).is('.pin'))
return;

this.are_labels_visible = !this.are_labels_visible;
this.is_label_bar_visible = !this.is_label_bar_visible;
this.update();
});
$('[name="show-help"]').click(e => {
Expand Down Expand Up @@ -368,7 +368,7 @@ class GUI {
}

get is_table_view() {
return manager.current.is_table_view;
return manager.current ? manager.current.is_table_view : false;
}
set is_table_view(bool) {

Expand All @@ -378,6 +378,20 @@ class GUI {

return manager.current.is_table_view;
}
get is_ltr() {
return manager.current ? manager.current.is_ltr : true;
}
set is_ltr(bool) {
if (manager.current)
manager.current.is_ltr = bool;
}
get is_vertical() {
return manager.current ? manager.current.is_vertical : false;
}
set is_vertical(bool) {
if (manager.current)
manager.current.is_vertical = bool;
}

column_visible(col, bool) {
if (typeof bool === 'boolean')
Expand Down
2 changes: 1 addition & 1 deletion client/labels.js
Expand Up @@ -495,7 +495,7 @@ class Labeler {
});

this._filter = new Set();
_.each(state.filter, name => {
state.filter.forEach(name => {
this.addFilter(name);
});
}
Expand Down
42 changes: 28 additions & 14 deletions client/manager.js
Expand Up @@ -36,12 +36,14 @@ class Manager {

reset() {
this.filename = cfg.defaultFilename;
this.options = {};

this._sentences = [];
this._index = -1;

this._filtered = [];
this._filterIndex = null;
this.insertSentence();
}
get length() {
return this._sentences.length;
Expand Down Expand Up @@ -366,48 +368,60 @@ class Manager {

get state() {
return {
index: this._index,
labeler: labeler.state,
options: this.options,
sentences: this._sentences.map(sent => sent.state),
meta: {
current_index: this.index,
//owner: this.users.owner,
//github_url: this.users.github_url,
gui: gui.state,
labeler: labeler.state,
//permissions: this.users.permissions,
//editors: this.users.editors
pinned_menu_items: gui.menu.state,
is_textarea_visible: gui.is_textarea_visible,
is_label_bar_visible: gui.is_label_bar_visible,
filename: this.filename,
},
sentences: this.map((i, sent) => sent.state)
};
}

set state(state) {

console.info('LOADING STATE', state);
this._index = state.meta.current_index;
this._sentences = state.sentences.map(state => {

let sent = new Sentence();
this.options = state.options;
this._sentences = state.sentences.map((state, i) => {

console.log('loading', i)
const sent = new Sentence();
sent.state = state;
return sent;

});
this._index = state.index;

if (!this.current)
this.insertSentence(cfg.defaultSentence);

// update users stuff
//this.users.state = _.pick(state.meta, ['owner', 'github_url', 'permissions', 'editors']);

labeler.state = state.meta.labeler;
labeler.state = state.labeler;
this.updateFilter(); // use the filters set in labeler

// this triggers a gui refresh
gui.state = state.meta.gui;
gui.menu.state = state.meta.pinned_menu_items;
gui.is_textarea_visible = state.meta.is_textarea_visible;
gui.is_label_bar_visible = state.meta.is_label_bar_visible;
this.filename = state.meta.filename;

gui.update();
}

save() {

status.normal('saving...');

if (!manager.current || !manager.current.parsed) {
status.error('Unable to save: no current parsed sentence')
return;
}

const state = JSON.stringify(this.state);

storage.save(state);
Expand Down
45 changes: 28 additions & 17 deletions client/sentence.js
Expand Up @@ -4,15 +4,13 @@ const _ = require('underscore');
const nx = require('notatrix');
const errors = require('./errors');
const status = require('./status');
const funcs = require('./funcs');

function encode(serial, options) {
try {

let format = detectFormat(serial, options)

if (format === 'notatrix serial')
format = 'CoNLL-U';

options = _.extend({
interpretAs: format,
allowEmptyString: true,
Expand All @@ -27,6 +25,7 @@ function encode(serial, options) {

if (e instanceof nx.NotatrixError) {

//debugger;
console.log(e);
gui.status.error('Unable to interpret input, disabling autoparsing and unsyncing')
return null;
Expand All @@ -51,7 +50,6 @@ function detectFormat(serial, options) {
});

if (formats.length === 0) {

throw new nx.NotatrixError('Unable to interpret input');

} else if (formats.indexOf('notatrix serial') > -1) {
Expand Down Expand Up @@ -110,8 +108,10 @@ class Sentence {
}

this.conversion_warning = null;
this.is_table_view = false;
this.column_visibilities = new Array(10).fill(true);
this.is_table_view = false;
this.is_ltr = true;
this.is_vertical = false;

labeler.parse(this._nx.comments);

Expand All @@ -122,6 +122,8 @@ class Sentence {
if (!this.parsed)
throw new Error('cannot cast unparsed text to string');

if (this.format === 'notatrix serial')
this.format = 'plain text';
format = format || this.format;

try {
Expand Down Expand Up @@ -218,22 +220,31 @@ class Sentence {
}

get state() {
return {
column_visibilities: this.column_visibilities,
format: this.format,
is_table_view: this.is_table_view,
nx: this._nx.to.notatrixSerial,
input: this._input
};

const state = this._nx.serialize();
state.meta.format = this.format;
state.meta.is_table_view = gui.is_table_view;
state.meta.is_ltr = gui.is_ltr;
state.meta.is_vertical = gui.is_vertical;
state.meta.column_visibilities = this.column_visibilities;
state.meta.pan = gui.pan;
state.meta.zoom = gui.zoom;

return state;
}

set state(state) {

this._input = state.input;
this.column_visibilities = state.column_visibilities;
this.format = state.format;
this.is_table_view = state.is_table_view;
this._nx = new nx.Sentence(state.nx);
const options = _.defaults(state.options, manager.options);
this.update(state, options);
this.format = state.meta.format || this.format;
this.column_visibilities = state.meta.column_visibilities || this.column_visibilities;
this.is_table_view = state.meta.is_table_view || this.is_table_view;
this.is_ltr = state.meta.is_ltr || this.is_ltr;
this.is_vertical = state.meta.is_vertical || this.is_vertical;

gui.pan = state.meta.pan;
gui.zoom = state.meta.zoom;

return this;
}
Expand Down
4 changes: 0 additions & 4 deletions client/test/data/conllu.corpus
Expand Up @@ -7,10 +7,6 @@
5 sentence sentence _ _ _ _ _ _ _
6 . . PUNCT PUNCT _ _ _ _ _

# labels = one_label second third-label
# labels = row_2 again:here this, that
1 This This _ _ _ _ _ _ _

# tags = this-is-a-tag test testing test
1 This This _ _ _ _ _ _ _

Expand Down
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -17,7 +17,7 @@
"mkdirp": "^0.5.1",
"morgan": "^1.9.0",
"nocache": "^2.0.0",
"notatrix": "^2.1.3",
"notatrix": "github:keggsmurph21/notatrix",
"popper": "^1.0.1",
"request": "^2.87.0",
"socket.io": "^2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion server/app.js
Expand Up @@ -15,7 +15,7 @@ const nocache = require('nocache');
const session = require('express-session');
const MemoryStore = new session.MemoryStore();
app.use(morgan(cfg.environment === 'development' ? 'dev' : 'tiny'));
app.use(bodyParser.json());
app.use(bodyParser.json({ limit: '500mb' }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(fileUpload());
Expand Down

0 comments on commit 459ac1d

Please sign in to comment.