Skip to content

Commit

Permalink
Added sort order of taskbar by using sortable.
Browse files Browse the repository at this point in the history
  • Loading branch information
martini committed Jun 1, 2013
1 parent dd4652b commit 3732105
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
18 changes: 18 additions & 0 deletions app/assets/javascripts/app/controllers/task_widget.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ class App.TaskWidget extends App.Controller
taskBarActions: @_getTaskActions()
)

dndOptions =
tolerance: 'pointer'
distance: 15
opacity: 0.6
forcePlaceholderSize: true
items: '> a'
update: =>
items = @el.find('.taskbar > a')
order = []
for item in items
key = $(item).data('key')
if !key
throw "No such key attributes found for task item"
order.push key
App.TaskManager.reorder( order )

@el.find( '.taskbar' ).sortable( dndOptions )

remove: (e) =>
e.preventDefault()
key = $(e.target).parent().data('key')
Expand Down
22 changes: 21 additions & 1 deletion app/assets/javascripts/app/lib/app_post/task_manager.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class App.TaskManager
_instance ?= new _Singleton
_instance.notify( key )

@reorder: ( order ) ->
if _instance == undefined
_instance ?= new _Singleton
_instance.reorder( order )

@reset: ->
if _instance == undefined
_instance ?= new _Singleton
Expand All @@ -59,7 +64,11 @@ class _Singleton extends App.Controller
@tasksInitial()

all: ->
App.Taskbar.all()
tasks = App.Taskbar.all()
tasks = _(tasks).sortBy( (task) ->
return task.prio;
)
return tasks

worker: ( key ) ->
return @workers[ key ] if @workers[ key ]
Expand All @@ -83,6 +92,7 @@ class _Singleton extends App.Controller
params: params
callback: callback
client_id: 123
prio: App.Taskbar.count() + 1
notify: false
active: active
)
Expand Down Expand Up @@ -213,6 +223,16 @@ class _Singleton extends App.Controller
task.save()
App.Event.trigger 'ui:rerender'

reorder: ( order ) =>
prio = 0
for key in order
task = @get( key )
if !task
throw "No such task with '#{key}' of order"
prio++
task.prio = prio
task.save()

reset: =>
App.Taskbar.deleteAll()
App.Event.trigger 'ui:rerender'
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/app/models/taskbar.js.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class App.Taskbar extends App.Model
@configure 'Taskbar', 'key', 'client_id', 'callback', 'state', 'params', 'notify', 'active'
@configure 'Taskbar', 'key', 'client_id', 'callback', 'state', 'params', 'prio', 'notify', 'active'
# @extend Spine.Model.Local
@extend Spine.Model.Ajax
@url: 'api/taskbar'
9 changes: 5 additions & 4 deletions db/migrate/20130529124443_taskbar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ class Taskbar < ActiveRecord::Migration
def up
create_table :taskbars do |t|
t.column :user_id, :integer, :null => false
t.column :last_contact, :datetime, :null => false
t.column :client_id, :string, :null => false
t.column :last_contact, :datetime, :null => false
t.column :client_id, :string, :null => false
t.column :key, :string, :limit => 100, :null => false
t.column :callback, :string, :limit => 100, :null => false
t.column :state, :string, :limit => 8000, :null => true
t.column :params, :string, :limit => 2000, :null => true
t.column :state, :string, :limit => 8000, :null => true
t.column :params, :string, :limit => 2000, :null => true
t.column :prio, :integer, :null => false
t.column :notify, :boolean, :null => false, :default => false
t.column :active, :boolean, :null => false, :default => false
t.timestamps
Expand Down

0 comments on commit 3732105

Please sign in to comment.