Skip to content

Commit

Permalink
Merge branch 'release/0.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
towerhe committed Jan 13, 2013
2 parents e77fd0a + c9c8ef0 commit 18a7dc8
Show file tree
Hide file tree
Showing 26 changed files with 97 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
task-manager (0.1.5)
task-manager (0.1.6)
active_model_serializers (~> 0.6.0)
activerecord-postgres-hstore (~> 0.4.1)
default_value_for (~> 2.0.1)
Expand Down
19 changes: 19 additions & 0 deletions app/assets/javascripts/task-manager/extjs/app/controller/Plans.js
Expand Up @@ -22,6 +22,9 @@ Ext.define('TM.controller.Plans', {
}, {
ref: 'planGrid',
selector: 'plan_grid'
}, {
ref: 'callbackCheckboxCombo',
selector: 'plan_form callback_checkboxcombo'
}],

index: function() {
Expand Down Expand Up @@ -53,10 +56,22 @@ Ext.define('TM.controller.Plans', {
},
'plan_form button[action="cancel"]': {
click: this.onCancelClick
},
'plan_form checkbox[name="autocompletable"]': {
change: this.onAutocompletableChange
}
});
},

onAutocompletableChange: function () {
record = this.getPlanForm().getValues().autocompletable;
if(record == "on"){
this.getCallbackCheckboxCombo().hide();
} else {
this.getCallbackCheckboxCombo().show();;
}
},

// @protected
onAddClick: function() {
Ext.create('TM.view.plan.FormWindow', { title: '添加计划' }).show();
Expand Down Expand Up @@ -107,6 +122,10 @@ Ext.define('TM.controller.Plans', {
var record = this.getPlanForm().getRecord() ||
Ext.create('TM.model.Plan');

if(attrs.autocompletable == "on") {
delete attrs["callables_attributes"];
}
attrs.autocompletable = attrs.autocompletable ? true: false;
record.set(attrs);
record.save({
success: function() {
Expand Down
Expand Up @@ -43,7 +43,7 @@ Ext.define('TM.controller.Tasks', {
// @protected
onDeleteClick: function(btn) {
var select = btn.up('task_grid').getSelectionModel().getSelection()[0];
if(select == null) {
if(select === null) {
Ext.Msg.alert('提示','请选择要删除的计划任务');
return;
}
Expand Down
Expand Up @@ -13,7 +13,7 @@ Ext.define('TM.helper.ApplicationHelper', {

translateStatus: function(s) {
var translations = {
new: '新建',
'new': '新建',
in_process: '进行中',
expired: '已过期',
finished: '已完成'
Expand Down
5 changes: 3 additions & 2 deletions app/assets/javascripts/task-manager/extjs/app/model/Task.js
Expand Up @@ -7,6 +7,7 @@ Ext.define('TM.model.Task', {
{ name: 'task_type'},
{ name: 'data', type: 'auto' },
{ name: 'status' },
{ name: 'assignee', type: 'auto', persist: false },
{ name: 'deadline', type: 'date'},
{ name: 'created_at', type: 'date' },
{ name: 'updated_at', type: 'date' }
Expand All @@ -19,5 +20,5 @@ Ext.define('TM.model.Task', {
root: 'tasks',
totalProperty: 'total'
}
},
});
}
});
Expand Up @@ -37,7 +37,7 @@ Ext.define('TM.store.Assignees', {
var parent = this.getNodeById(assignee.getParentId(true)) || this.getRootNode();
var node = parent.findChild('id', assignee.getId(true));

if(!node) this.appendChildNode(parent, assignee);
if(!node) { this.appendChildNode(parent, assignee); }
}, this);
},

Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/task-manager/extjs/app/store/Months.js
Expand Up @@ -14,6 +14,6 @@ Ext.define('TM.store.Months',{
{ "text": "9月", 'value': '09' },
{ "text": "10月", 'value': '10' },
{ "text": "11月", 'value': '11' },
{ "text": "12月", 'value': '12' },
{ "text": "12月", 'value': '12' }
]
});
});
Expand Up @@ -18,18 +18,20 @@ Ext.define('TM.view.assignee.TreeCombo', {

getSubmitValue: function() {
var value = [];
if(!this.value) return value;
if(!this.value) { return value; }

var objs = this.value.split(',');
objs.forEach(function(i) {
var node = this.tree.getStore().getNodeById(i);
if(node) {
var assignee = node.raw.record;
var attrs = {
assignee_id: assignee.get('id'),
assignee_type: assignee.get('class_name')
};
value.push(attrs);
if (assignee) {
var attrs = {
assignee_id: assignee.get('id'),
assignee_type: assignee.get('class_name')
};
value.push(attrs);
}
}
}, this);

Expand Down
31 changes: 27 additions & 4 deletions app/assets/javascripts/task-manager/extjs/app/view/plan/Form.js
Expand Up @@ -31,16 +31,17 @@ Ext.define('TM.view.plan.Form', {
}, {
xtype: 'assignee_treecombo',
fieldLabel: '执行人',
allowBlank: false,
name: 'assignables_attributes',
store: Ext.getStore('TM.store.Assignees').toTreeStore()
}, {
fieldLabel: '类型',
fieldLabel: '周期',
name: 'plan_type',
store: 'TM.store.Types',
editable: false,
valueField: 'value',
xtype: 'combo',
blankText: '请选择类型!',
blankText: '请选择周期',
allowBlank: false
}, {
fieldLabel: '横向指标',
Expand Down Expand Up @@ -77,13 +78,13 @@ Ext.define('TM.view.plan.Form', {
}, {
xtype: 'fieldset',
itemId: 'deadline',
title: '截止时间',
title: '完成时限',
layout: {
type: 'table',
columns: 2
},
defaults: {
labelAlign: 'right',
labelAlign: 'right'
},
items: [{
fieldLabel: '月',
Expand Down Expand Up @@ -254,6 +255,7 @@ Ext.define('TM.view.plan.Form', {
bindStore(Ext.getStore('TM.store.Days'));

this.showDeadlineCombos(["month", "day", "hour", "minute"]);
this.requireDeadlineCombos(["month", "day", "hour", "minute"]);
},

// @private
Expand All @@ -264,6 +266,7 @@ Ext.define('TM.view.plan.Form', {
bindStore(Ext.getStore('TM.store.Days'));

this.showDeadlineCombos(["month", "day", "hour", "minute"]);
this.requireDeadlineCombos(["month", "day", "hour", "minute"]);
},

// @private
Expand All @@ -273,6 +276,8 @@ Ext.define('TM.view.plan.Form', {

this.showDeadlineCombos(["day", "hour", "minute"]);
this.hideDeadlineCombos(["month"]);
this.requireDeadlineCombos(["day", "hour", "minute"]);
this.allowBlankDeadlineCombos(["month"]);
},

// @private
Expand All @@ -282,12 +287,16 @@ Ext.define('TM.view.plan.Form', {

this.showDeadlineCombos(["day", "hour", "minute"]);
this.hideDeadlineCombos(["month"]);
this.requireDeadlineCombos(["day", "hour", "minute"]);
this.allowBlankDeadlineCombos(["month"]);
},

// @private
showDailyDeadlineCombos: function() {
this.showDeadlineCombos(["hour", "minute"]);
this.hideDeadlineCombos(["month", "day"]);
this.requireDeadlineCombos(["hour", "minute"]);
this.allowBlankDeadlineCombos(["month","day"]);
},

// @private
Expand All @@ -309,6 +318,20 @@ Ext.define('TM.view.plan.Form', {
}, this);
},

// @private
requireDeadlineCombos: function(combos) {
combos.forEach(function(c) {
this.getDeadlineCombo('data.deadline_' + c).allowBlank = false;
}, this);
},

// @private
allowBlankDeadlineCombos: function(combos) {
combos.forEach(function(c) {
this.getDeadlineCombo('data.deadline_' + c).allowBlank = true;
}, this);
},

// @private
getAssigneesTreeCombo: function() {
return this.query('assignee_treecombo')[0];
Expand Down
Expand Up @@ -32,7 +32,7 @@ Ext.define('TM.view.plan.Grid', {
'<table class="data">',
'<tr>',
'<td rowspan="3" class="title">内容</td>',
'<td class="name">截止时间:</td>',
'<td class="name">完成时限:</td>',
'<td class="value">第{[values.data.deadline_month == null ? 0 : values.data.deadline_month]}',
'个月,第{[values.data.deadline_day == null ? 0 : values.data.deadline_day]}天,',
'{data.deadline_hour}时{data.deadline_minute}分</td>',
Expand All @@ -45,7 +45,7 @@ Ext.define('TM.view.plan.Grid', {
'<td class="name">纵向指标:</td>',
'<td class="value">{[values.data.y == null ? "" : values.data.y]}</td>',
'</tr>',
'</table>',
'</table>'
]
}],

Expand All @@ -54,7 +54,7 @@ Ext.define('TM.view.plan.Grid', {
dataIndex: 'name',
flex: 2
}, {
text: '类型',
text: '周期',
dataIndex: 'plan_type',
renderer: function(v, m, record) {
return this.translateType(v);
Expand Down
Expand Up @@ -19,6 +19,6 @@ Ext.define('TM.view.plan.Index', {
width: 50
}, {
xtype: 'plan_grid',
flex: 1,
flex: 1
}]
});
Expand Up @@ -30,7 +30,7 @@ Ext.define('TM.view.plan.Search', {
fieldLabel: '名称',
name: 'q[name_cont]'
}, {
fieldLabel: '类型',
fieldLabel: '周期',
editable: false,
xtype: 'combo',
store: 'TM.store.Types',
Expand Down Expand Up @@ -112,7 +112,7 @@ Ext.define('TM.view.plan.Search', {
action: 'reset'
}]
}]
}],
}]
}]
}],

Expand Down
Expand Up @@ -38,7 +38,7 @@ Ext.define('TM.view.task.Grid', {
dataIndex: 'name',
flex: 2
}, {
text: '类型',
text: '周期',
dataIndex: 'task_type',
renderer: function(v, m, record) {
return this.translateType(v);
Expand All @@ -52,7 +52,7 @@ Ext.define('TM.view.task.Grid', {
},
flex:2
}, {
text: '截止时间',
text: '完成时限',
dataIndex: 'deadline',
renderer: function(v, m, record) {
return Ext.Date.format(v, 'Y年m月j日 H:i:s');
Expand Down
Expand Up @@ -18,4 +18,4 @@ Ext.define('TM.view.task.Index', {
xtype: 'task_grid',
flex: 1
}]
})
});
Expand Up @@ -31,7 +31,7 @@ Ext.define('TM.view.task.Search', {
fieldLabel: '名称',
name: 'q[name_cont]'
}, {
fieldLabel: '类型',
fieldLabel: '周期',
editable: false,
xtype: 'combo',
id: 'types',
Expand Down
Expand Up @@ -124,5 +124,5 @@ Ext.define('Ext.ux.form.CheckboxListCombo', {
}
}
}
},
}
});

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

2 changes: 1 addition & 1 deletion app/controllers/task_manager/api/v1/plans_controller.rb
Expand Up @@ -9,7 +9,7 @@ class PlansController < TaskManager::ApplicationController
#
# 支持的查询属性有:
# name 计划名
# plan_type 计划类型
# plan_type 计划周期
# autocompletable 是否自动完成
# last_task_created_at 最后任务生成时间
# enabled_at 生效时间
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/task_manager/api/v1/tasks_controller.rb
Expand Up @@ -9,8 +9,8 @@ class TasksController < TaskManager::ApplicationController
#
# 支持的查询属性有:
# name 任务名
# task_type 任务类型
# deadline 截止时间
# task_type 任务周期
# deadline 完成时限
# status 状态
# updated_at 完成时间
#
Expand Down
10 changes: 3 additions & 7 deletions app/models/task_manager/plan.rb
Expand Up @@ -53,20 +53,16 @@ def generate_task_for_assignable(a)
data.symbolize_keys!

reminding_at = default_deadline.ago(begin_to_remind * 60)
if autocompletable
status, finished_at = :finished, Time.now
else
status, finished_at = :new, nil
end

Task.create! do |t|
t.name = name
t.data = data.select{ |k, v| !(k.to_s.start_with?('deadline_')) }
t.task_type = plan_type
t.deadline = calculate_deadline(plan_type, data)
t.reminding_at = reminding_at
t.status = status
t.finished_at = finished_at
t.status = :new
t.finished_at = nil
t.autocompletable = autocompletable
t.create_assignable(
assignee_id: a.assignee_id,
assignee_type: a.assignee_type,
Expand Down
7 changes: 6 additions & 1 deletion app/models/task_manager/task.rb
Expand Up @@ -13,7 +13,8 @@ class Task < ActiveRecord::Base

default_value_for :status, :new

attr_accessible :data, :deadline, :name, :reminding_at, :status, :task_type, :finished_at
attr_accessible :data, :deadline, :name, :reminding_at, :status,
:task_type, :finished_at, :autocompletable

validates_presence_of :name, :task_type, :status, :assignable, :deadline

Expand Down Expand Up @@ -76,6 +77,10 @@ def just_expired
def remindable
active.where("reminding_at <= ?", Time.now)
end

def autocompletable
where(autocompletable: true)
end
end
end
end

0 comments on commit 18a7dc8

Please sign in to comment.