mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-01 11:33:41 +03:00
restore inline new-item creation, just don't persist it
This commit is contained in:
parent
2ed238a5f7
commit
45591d9c5b
@ -258,7 +258,7 @@
|
||||
::
|
||||
++ mirror-to-web
|
||||
^- [(list move) _.]
|
||||
~& [%mirroring tasks=tasks sort=sort]
|
||||
~& [%mirroring sort=(turn sort |=(a=@uv `@uv`(rsh 2 25 a)))]
|
||||
:_ .
|
||||
%+ murn (~(tap by sup))
|
||||
|= [ust=bone her=ship pax=path]
|
||||
|
@ -56,6 +56,7 @@
|
||||
==
|
||||
++ task
|
||||
%- ot :~
|
||||
::index/ni
|
||||
audience/audi
|
||||
id/id 'date_created'^di
|
||||
version/ni 'date_modified'^di
|
||||
|
@ -1,14 +1,15 @@
|
||||
Dispatcher = require '../dispatcher/Dispatcher.coffee'
|
||||
Persistence = require '../persistence/Persistence.coffee'
|
||||
|
||||
{uuid32} = require '../util.coffee'
|
||||
|
||||
module.exports =
|
||||
newItem: (index,_item={}) ->
|
||||
item =
|
||||
date_created: Date.now()
|
||||
date_modified: Date.now()
|
||||
owner: window.urb.ship
|
||||
version: 0
|
||||
id: _item.id ? window.util.uuid32()
|
||||
version: -1
|
||||
id: _item.id ? uuid32()
|
||||
date_due: _item.date_due ? null
|
||||
done: _item.done ? null
|
||||
status: _item.status ? 'announced'
|
||||
@ -18,7 +19,9 @@ module.exports =
|
||||
discussion: _item.discussion ? []
|
||||
audience: _item.audience ?
|
||||
[window.util.talk.mainStationPath window.urb.ship]
|
||||
Persistence.put new:item
|
||||
if item.date_due or item.title or item.description
|
||||
item.version++
|
||||
Persistence.put new:item
|
||||
Dispatcher.handleViewAction {type:'newItem', index, item}
|
||||
|
||||
setItem: ({id,version},key,val) ->
|
||||
@ -26,6 +29,8 @@ module.exports =
|
||||
key = key.split('_').join '-'
|
||||
set = "#{key}": val
|
||||
Persistence.put old:{id,version,dif:{set}}
|
||||
Dispatcher.handleViewAction {type:'updateItem',id,version}
|
||||
|
||||
|
||||
ownItem: ({id,version},own) ->
|
||||
o = {}
|
||||
@ -52,8 +57,6 @@ module.exports =
|
||||
sort.splice to, 0, sort.splice(from,1)[0]
|
||||
Persistence.put {sort}
|
||||
Dispatcher.handleViewAction {type:'moveItems',list:sort,to,from}
|
||||
|
||||
moveGhost: (index)-> Dispatcher.handleViewAction {type:'moveGhost',index}
|
||||
|
||||
listenList: (type)->
|
||||
Persistence.subscribe type, (err,d)->
|
||||
|
@ -48,10 +48,12 @@ module.exports = recl
|
||||
if @to then clearTimeout @to
|
||||
@to = setTimeout =>
|
||||
{item,_key} = @props
|
||||
if not item.ghost
|
||||
if item.version >= 0
|
||||
WorkActions.setItem item, _key, val
|
||||
else WorkActions.newItem item.index,
|
||||
id: item.id
|
||||
id: item.id
|
||||
tags: item.tags
|
||||
audience: item.audience
|
||||
"#{_key}": val
|
||||
,1000
|
||||
|
||||
|
@ -58,7 +58,9 @@ module.exports = recl
|
||||
WorkActions.addComment @props.item,val
|
||||
$input.text('')
|
||||
|
||||
formatDate: (d=(new Date),l) ->
|
||||
formatDate: (d,l) ->
|
||||
unless d
|
||||
return ""
|
||||
_d = "~#{d.getFullYear()}.#{(d.getMonth()+1)}.#{d.getDate()}"
|
||||
if l
|
||||
_d += "..#{d.getHours()}.#{d.getMinutes()}.#{d.getSeconds()}"
|
||||
@ -80,7 +82,7 @@ module.exports = recl
|
||||
|
||||
componentDidMount: ->
|
||||
setInterval =>
|
||||
$('.new.comment .date').text @formatDate()
|
||||
$('.new.comment .date').text @formatDate new Date
|
||||
, 1000
|
||||
|
||||
render: ->
|
||||
@ -141,7 +143,7 @@ module.exports = recl
|
||||
(div {className:'new comment'},
|
||||
(div {className:'hr2'},"")
|
||||
(div {className:'ship ib'}, window.urb.ship)
|
||||
(div {className:'date ib'}, @formatDate())
|
||||
(div {className:'date ib'}, @formatDate new Date)
|
||||
(div {
|
||||
contentEditable:true,
|
||||
className:'input'})
|
||||
|
@ -62,14 +62,15 @@ module.exports = recl
|
||||
switch kc
|
||||
# enter - add new
|
||||
when 13
|
||||
{index} = i.props
|
||||
{index,item} = i.props
|
||||
if window.getSelection().getRangeAt(0).endOffset is 0
|
||||
ins = @state.selected
|
||||
else
|
||||
index++
|
||||
ins = @state.selected+1 # XX consolidate
|
||||
@setState {selected:ins,select:true}
|
||||
WorkActions.moveGhost index
|
||||
{tags,audience} = item
|
||||
WorkActions.newItem index, {tags,audience}
|
||||
# backspace - remove if at 0
|
||||
when 8
|
||||
if (window.getSelection().getRangeAt(0).endOffset is 0) and
|
||||
|
@ -1,10 +1,12 @@
|
||||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||
var Dispatcher, Persistence;
|
||||
var Dispatcher, Persistence, uuid32;
|
||||
|
||||
Dispatcher = require('../dispatcher/Dispatcher.coffee');
|
||||
|
||||
Persistence = require('../persistence/Persistence.coffee');
|
||||
|
||||
uuid32 = require('../util.coffee').uuid32;
|
||||
|
||||
module.exports = {
|
||||
newItem: function(index, _item) {
|
||||
var item, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8;
|
||||
@ -15,8 +17,8 @@ module.exports = {
|
||||
date_created: Date.now(),
|
||||
date_modified: Date.now(),
|
||||
owner: window.urb.ship,
|
||||
version: 0,
|
||||
id: (ref = _item.id) != null ? ref : window.util.uuid32(),
|
||||
version: -1,
|
||||
id: (ref = _item.id) != null ? ref : uuid32(),
|
||||
date_due: (ref1 = _item.date_due) != null ? ref1 : null,
|
||||
done: (ref2 = _item.done) != null ? ref2 : null,
|
||||
status: (ref3 = _item.status) != null ? ref3 : 'announced',
|
||||
@ -26,9 +28,12 @@ module.exports = {
|
||||
discussion: (ref7 = _item.discussion) != null ? ref7 : [],
|
||||
audience: (ref8 = _item.audience) != null ? ref8 : [window.util.talk.mainStationPath(window.urb.ship)]
|
||||
};
|
||||
Persistence.put({
|
||||
"new": item
|
||||
});
|
||||
if (item.date_due || item.title || item.description) {
|
||||
item.version++;
|
||||
Persistence.put({
|
||||
"new": item
|
||||
});
|
||||
}
|
||||
return Dispatcher.handleViewAction({
|
||||
type: 'newItem',
|
||||
index: index,
|
||||
@ -45,7 +50,7 @@ module.exports = {
|
||||
obj["" + key] = val,
|
||||
obj
|
||||
);
|
||||
return Persistence.put({
|
||||
Persistence.put({
|
||||
old: {
|
||||
id: id,
|
||||
version: version,
|
||||
@ -54,6 +59,11 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
});
|
||||
return Dispatcher.handleViewAction({
|
||||
type: 'updateItem',
|
||||
id: id,
|
||||
version: version
|
||||
});
|
||||
},
|
||||
ownItem: function(arg, own) {
|
||||
var id, o, version;
|
||||
@ -144,12 +154,6 @@ module.exports = {
|
||||
from: from
|
||||
});
|
||||
},
|
||||
moveGhost: function(index) {
|
||||
return Dispatcher.handleViewAction({
|
||||
type: 'moveGhost',
|
||||
index: index
|
||||
});
|
||||
},
|
||||
listenList: function(type) {
|
||||
return Persistence.subscribe(type, function(err, d) {
|
||||
var ref, sort, tasks;
|
||||
@ -167,7 +171,7 @@ module.exports = {
|
||||
|
||||
|
||||
|
||||
},{"../dispatcher/Dispatcher.coffee":9,"../persistence/Persistence.coffee":15}],2:[function(require,module,exports){
|
||||
},{"../dispatcher/Dispatcher.coffee":9,"../persistence/Persistence.coffee":15,"../util.coffee":17}],2:[function(require,module,exports){
|
||||
var WorkActions, div, rece, recl, ref, textarea,
|
||||
slice = [].slice;
|
||||
|
||||
@ -240,12 +244,14 @@ module.exports = recl({
|
||||
return function() {
|
||||
var _key, item, obj, ref1;
|
||||
ref1 = _this.props, item = ref1.item, _key = ref1._key;
|
||||
if (!item.ghost) {
|
||||
if (item.version >= 0) {
|
||||
return WorkActions.setItem(item, _key, val);
|
||||
} else {
|
||||
return WorkActions.newItem(item.index, (
|
||||
obj = {
|
||||
id: item.id
|
||||
id: item.id,
|
||||
tags: item.tags,
|
||||
audience: item.audience
|
||||
},
|
||||
obj["" + _key] = val,
|
||||
obj
|
||||
@ -520,8 +526,8 @@ module.exports = recl({
|
||||
},
|
||||
formatDate: function(d, l) {
|
||||
var _d;
|
||||
if (d == null) {
|
||||
d = new Date;
|
||||
if (!d) {
|
||||
return "";
|
||||
}
|
||||
_d = "~" + (d.getFullYear()) + "." + (d.getMonth() + 1) + "." + (d.getDate());
|
||||
if (l) {
|
||||
@ -569,7 +575,7 @@ module.exports = recl({
|
||||
componentDidMount: function() {
|
||||
return setInterval((function(_this) {
|
||||
return function() {
|
||||
return $('.new.comment .date').text(_this.formatDate());
|
||||
return $('.new.comment .date').text(_this.formatDate(new Date));
|
||||
};
|
||||
})(this), 1000);
|
||||
},
|
||||
@ -662,7 +668,7 @@ module.exports = recl({
|
||||
className: 'ship ib'
|
||||
}, window.urb.ship), div({
|
||||
className: 'date ib'
|
||||
}, this.formatDate()), div({
|
||||
}, this.formatDate(new Date)), div({
|
||||
contentEditable: true,
|
||||
className: 'input'
|
||||
}), div({
|
||||
@ -773,11 +779,11 @@ module.exports = recl({
|
||||
}
|
||||
},
|
||||
title_keyDown: function(e, i) {
|
||||
var index, ins, kc, last, next;
|
||||
var audience, index, ins, item, kc, last, next, ref1, tags;
|
||||
kc = e.keyCode;
|
||||
switch (kc) {
|
||||
case 13:
|
||||
index = i.props.index;
|
||||
ref1 = i.props, index = ref1.index, item = ref1.item;
|
||||
if (window.getSelection().getRangeAt(0).endOffset === 0) {
|
||||
ins = this.state.selected;
|
||||
} else {
|
||||
@ -788,7 +794,11 @@ module.exports = recl({
|
||||
select: true
|
||||
});
|
||||
}
|
||||
WorkActions.moveGhost(index);
|
||||
tags = item.tags, audience = item.audience;
|
||||
WorkActions.newItem(index, {
|
||||
tags: tags,
|
||||
audience: audience
|
||||
});
|
||||
break;
|
||||
case 8:
|
||||
if ((window.getSelection().getRangeAt(0).endOffset === 0) && (e.target.innerText.length === 0)) {
|
||||
@ -1485,7 +1495,9 @@ WorkStore = assign({}, EventEmitter.prototype, {
|
||||
if (!_tasks[id]) {
|
||||
_list.splice(index, 0, id);
|
||||
}
|
||||
if (tasks[id]) {
|
||||
if (!tasks[id]) {
|
||||
return console.log("lost", id);
|
||||
} else if (!_tasks[id] || tasks[id].version > _tasks[id].version) {
|
||||
return _tasks[id] = _this.itemFromData(tasks[id], index);
|
||||
}
|
||||
};
|
||||
@ -1501,7 +1513,7 @@ WorkStore = assign({}, EventEmitter.prototype, {
|
||||
for (i = 0, len = _list.length; i < len; i++) {
|
||||
id = _list[i];
|
||||
task = _tasks[id];
|
||||
if (task.archived) {
|
||||
if ((task == null) || task.archived) {
|
||||
continue;
|
||||
}
|
||||
add = true;
|
||||
@ -1545,12 +1557,15 @@ WorkStore = assign({}, EventEmitter.prototype, {
|
||||
}
|
||||
}
|
||||
if (!(((_filters.owner != null) && _filters.owner !== urb.ship) || (_filters.done != null))) {
|
||||
ghost = $.extend({}, _ghost, {
|
||||
ghost = $.extend({
|
||||
ghost: true,
|
||||
version: -1
|
||||
});
|
||||
if (ghost.index != null) {
|
||||
list.splice(ghost.index, 0, ghost);
|
||||
}, _ghost);
|
||||
if (_filters.tags) {
|
||||
ghost.tags = _filters.tags;
|
||||
}
|
||||
if (_filters.audience) {
|
||||
ghost.audience = _filters.audience;
|
||||
} else {
|
||||
list.push(ghost);
|
||||
}
|
||||
@ -1560,13 +1575,17 @@ WorkStore = assign({}, EventEmitter.prototype, {
|
||||
newItem: function(arg) {
|
||||
var index, item;
|
||||
index = arg.index, item = arg.item;
|
||||
if (item.id = _ghost.id) {
|
||||
_ghost.id = uuid32();
|
||||
}
|
||||
if (index == null) {
|
||||
index = _list.length;
|
||||
}
|
||||
_list.splice(index, 0, item.id);
|
||||
if (item.id === _ghost.id) {
|
||||
_ghost.id = uuid32();
|
||||
}
|
||||
if (_tasks[item.id] == null) {
|
||||
_list.splice(index, 0, item.id);
|
||||
} else if (_tasks[item.id].version >= 0) {
|
||||
throw new Error("Collision: already have " + item.id);
|
||||
}
|
||||
return _tasks[item.id] = this.itemFromData(item, index);
|
||||
},
|
||||
getListening: function() {
|
||||
@ -1578,7 +1597,6 @@ WorkStore = assign({}, EventEmitter.prototype, {
|
||||
setFilter: function(arg) {
|
||||
var key, val;
|
||||
key = arg.key, val = arg.val;
|
||||
_ghost.index = null;
|
||||
return _filters[key] = val;
|
||||
},
|
||||
getSorts: function() {
|
||||
@ -1587,7 +1605,6 @@ WorkStore = assign({}, EventEmitter.prototype, {
|
||||
setSort: function(arg) {
|
||||
var k, key, v, val;
|
||||
key = arg.key, val = arg.val;
|
||||
_ghost.index = null;
|
||||
for (k in _sorts) {
|
||||
v = _sorts[k];
|
||||
_sorts[k] = 0;
|
||||
@ -1639,11 +1656,6 @@ WorkStore = assign({}, EventEmitter.prototype, {
|
||||
_tasks[_list[from]].sort = _tasks[_list[to]].sort;
|
||||
return _list = list;
|
||||
},
|
||||
moveGhost: function(arg) {
|
||||
var index;
|
||||
index = arg.index;
|
||||
return _ghost.index = index;
|
||||
},
|
||||
setAudience: function(arg) {
|
||||
var id, to;
|
||||
id = arg.id, to = arg.to;
|
||||
@ -1653,6 +1665,11 @@ WorkStore = assign({}, EventEmitter.prototype, {
|
||||
var id;
|
||||
id = arg.id;
|
||||
return _tasks[id].archived = true;
|
||||
},
|
||||
updateItem: function(arg) {
|
||||
var id, version;
|
||||
id = arg.id, version = arg.version;
|
||||
return _tasks[id].version = version;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -29,7 +29,9 @@ WorkStore = assign {},EventEmitter.prototype,{
|
||||
sort.map (id,index)=>
|
||||
unless _tasks[id]
|
||||
_list.splice index, 0, id
|
||||
if tasks[id] # XX client-side defaults
|
||||
if !tasks[id]
|
||||
console.log "lost", id
|
||||
else if !_tasks[id] or tasks[id].version > _tasks[id].version
|
||||
_tasks[id] = @itemFromData tasks[id], index
|
||||
_updated = Date.now()
|
||||
|
||||
@ -39,7 +41,7 @@ WorkStore = assign {},EventEmitter.prototype,{
|
||||
list = []
|
||||
for id in _list
|
||||
task = _tasks[id]
|
||||
if task.archived
|
||||
if !task? or task.archived
|
||||
continue
|
||||
add = true
|
||||
for _k,_v of _filters
|
||||
@ -63,27 +65,28 @@ WorkStore = assign {},EventEmitter.prototype,{
|
||||
list = _.sortBy list,k,k
|
||||
if v is -1 then list.reverse()
|
||||
unless (_filters.owner? and _filters.owner isnt urb.ship) or _filters.done?
|
||||
ghost = $.extend {}, _ghost, ghost:true, version:-1
|
||||
if ghost.index?
|
||||
list.splice ghost.index, 0, ghost
|
||||
ghost = $.extend {ghost:true,version:-1}, _ghost
|
||||
if _filters.tags then ghost.tags = _filters.tags
|
||||
if _filters.audience then ghost.audience = _filters.audience
|
||||
else list.push ghost
|
||||
list
|
||||
|
||||
newItem: ({index,item}) ->
|
||||
if item.id = _ghost.id
|
||||
_ghost.id = uuid32()
|
||||
index ?= _list.length
|
||||
_list.splice index,0,item.id
|
||||
if item.id is _ghost.id
|
||||
_ghost.id = uuid32()
|
||||
unless _tasks[item.id]?
|
||||
_list.splice index,0,item.id
|
||||
else if _tasks[item.id].version >= 0
|
||||
throw new Error "Collision: already have #{item.id}"
|
||||
_tasks[item.id] = @itemFromData item, index
|
||||
|
||||
getListening: -> _listening
|
||||
getFilters: -> _filters
|
||||
setFilter: ({key,val}) ->
|
||||
_ghost.index = null
|
||||
_filters[key] = val
|
||||
getSorts: -> _sorts
|
||||
setSort: ({key,val}) ->
|
||||
_ghost.index = null
|
||||
for k,v of _sorts
|
||||
_sorts[k] = 0
|
||||
_sorts[key] = val
|
||||
@ -109,9 +112,9 @@ WorkStore = assign {},EventEmitter.prototype,{
|
||||
moveItems: ({list,to,from}) ->
|
||||
_tasks[_list[from]].sort = _tasks[_list[to]].sort
|
||||
_list = list
|
||||
moveGhost: ({index})-> _ghost.index = index
|
||||
setAudience: ({id,to})-> _tasks[id].audience = to
|
||||
archiveItem: ({id})-> _tasks[id].archived = true
|
||||
updateItem: ({id,version})-> _tasks[id].version = version
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user