Permalink
Browse files

⚡️ sort/unsort button

  • Loading branch information...
KolushovAlexandr committed Jan 28, 2019
1 parent 7954195 commit 40bbc7e804448e984f6b50748452b3200a72e3c5
@@ -29,6 +29,7 @@
'security/project_security.xml'
],
"qweb": [
'static/src/xml/templates.xml'
],
"demo": [
'demo/project_task_subtask_demo.xml'
@@ -2,7 +2,7 @@
-------

**Improvement:** Status bar on tasks for project.task kanban view
**Improvement:** Automatically sorting subtasks
**Improvement:** Button to sort subtasks

`1.0.2`
-------
@@ -14,7 +14,7 @@

SUBTASK_STATES = {'done': 'Done',
'todo': 'TODO',
'waiting': 'In Progress',
'waiting': 'Waiting',
'cancelled': 'Cancelled'}


@@ -129,16 +129,16 @@ def _compute_kanban_subtasks(self):
result_string_td = ''
result_string_wt = ''
if record.subtask_ids:
task_todo_ids = record.subtask_ids.filtered(lambda x: x.state == 'todo' and (
x.user_id.id == record.env.user.id))
task_waiting_ids = record.subtask_ids.filtered(lambda x: x.state == 'waiting' and (
x.user_id.id == record.env.user.id))
task_todo_ids = record.subtask_ids.filtered(lambda x: x.state == 'todo' and
x.user_id.id == record.env.user.id)
task_waiting_ids = record.subtask_ids.filtered(lambda x: x.state == 'waiting' and
x.user_id.id == record.env.user.id)
if task_todo_ids:
tmp_string_td = escape(': {0}'.format(len(task_todo_ids)))
result_string_td += '<li><b>TODO{}</b></li>'.format(tmp_string_td)
if task_waiting_ids:
tmp_string_wt = escape(': {0}'.format(len(task_waiting_ids)))
result_string_wt += '<li><b>In Progress{}</b></li>'.format(tmp_string_wt)
result_string_wt += '<li><b>Waiting{}</b></li>'.format(tmp_string_wt)
record.kanban_subtasks = '<div class="kanban_subtasks"><ul>' + \
result_string_td + result_string_wt + '</ul></div>'

@@ -5,14 +5,17 @@ odoo.define('project_task_subtask.one2many_renderer', function(require){
var FieldOne2Many = require('web.relational_fields').FieldOne2Many;
var BasicModel = require('web.BasicModel');

var core = require('web.core');
var QWeb = core.qweb;

FieldOne2Many.include({

check_task_tree_mode: function(){
if (this.view &&
this.view.arch.tag === 'tree' &&
this.record && this.record.model === "project.task" &&
this.name === 'subtask_ids'
) {
this.view.arch.tag === 'tree' &&
this.record && this.record.model === "project.task" &&
this.name === 'subtask_ids'
) {
return true;
}
return false;
@@ -69,11 +72,12 @@ odoo.define('project_task_subtask.one2many_renderer', function(require){
_.each(new_rows, function(r){
data.push(r);
});
this.default_sorting = this.value.data;
this.value.data = data;
},

_render: function () {
if (this.check_task_tree_mode()) {
if (this.check_task_tree_mode() && this.getParent().list_is_sorted) {
this.sort_data();
}
return this._super(arguments);
@@ -82,12 +86,52 @@ odoo.define('project_task_subtask.one2many_renderer', function(require){
reset: function (record, ev, fieldChanged) {
var self = this;
return this._super.apply(this, arguments).then(function(res){
if (self.check_task_tree_mode()) {
if (self.check_task_tree_mode() && self.getParent().list_is_sorted) {
self._render();
}
});
},

_renderControlPanel: function () {
var self = this;
if (this.check_task_tree_mode()) {
this.$buttons = QWeb.render("SubtaskSortButtons", {});
return this._super(arguments).done(function(res){
self._update_custom_sort_buttons();
});
}
return this._super(arguments);
},

_update_custom_sort_buttons: function() {
var self = this;
var sort_button = this.$el.find('.o_pager_sort');
var unsort_button = this.$el.find('.o_pager_unsort');

var sorting = this.getParent().list_is_sorted || false;

if (sorting) {
sort_button.hide();
} else {
unsort_button.hide();
}
this.default_sorting = this.value.data;

sort_button.off().on('click', function(e){
self.getParent().list_is_sorted = true;
sort_button.hide();
unsort_button.show();
self._render();
});
unsort_button.off().on('click', function(e){
self.getParent().list_is_sorted = false;
sort_button.show();
unsort_button.hide();
self.value.data = self.default_sorting;
self._render();
});
},

});

BasicModel.include({
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).-->
<template xml:space="preserve">
<t t-name="SubtaskSortButtons">
<button aria-label="Sort" class="btn btn-sm btn-primary o_pager_sort" type="button">Sort</button>
<button aria-label="Unsort" class="btn btn-sm btn-default o_pager_unsort" type="button">Unsort</button>
</t>

</template>
@@ -23,7 +23,7 @@
<field name="hide_button" invisible='True'/>
<button name="change_state_done" string="Change state to DONE" type="object" icon="fa-check" attrs="{'invisible': ['|', ('state', 'in',['done', 'cancelled']), ('hide_button', '=', True)]}"/>
<button name="change_state_todo" string="Change state to TODO" type="object" icon="fa-caret-square-o-right" attrs="{'invisible': [ '|',('state', '=', 'todo'), ('hide_button', '=', True)]}"/>
<button name="change_state_waiting" type="object" string="Change state to In Progress" icon="fa-pause" attrs="{'invisible': [ '|',('state', '=', 'waiting'), ('hide_button', '=', True)]}"/>
<button name="change_state_waiting" type="object" string="Change state to Waiting" icon="fa-pause" attrs="{'invisible': [ '|',('state', '=', 'waiting'), ('hide_button', '=', True)]}"/>
<button name="change_state_cancelled" type="object" string="Change state to CANCELLED" icon="fa-ban" attrs="{'invisible': [ '|',('state', '=', 'cancelled'), ('hide_button', '=', True)]}"/>
<field name="reviewer_id"/>
<field name="deadline"/>

0 comments on commit 40bbc7e

Please sign in to comment.