Navigation Menu

Skip to content

Commit

Permalink
⚡ sort/unsort button
Browse files Browse the repository at this point in the history
  • Loading branch information
KolushovAlexandr committed Jan 28, 2019
1 parent 7954195 commit c3758b5
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 10 deletions.
1 change: 1 addition & 0 deletions project_task_subtask/__manifest__.py
Expand Up @@ -29,6 +29,7 @@
'security/project_security.xml'
],
"qweb": [
'static/src/xml/templates.xml'
],
"demo": [
'demo/project_task_subtask_demo.xml'
Expand Down
2 changes: 1 addition & 1 deletion project_task_subtask/doc/changelog.rst
Expand Up @@ -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`
-------
Expand Down
4 changes: 2 additions & 2 deletions project_task_subtask/models/project_task_subtask.py
Expand Up @@ -14,7 +14,7 @@

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


Expand Down Expand Up @@ -138,7 +138,7 @@ def _compute_kanban_subtasks(self):
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>'

Expand Down
56 changes: 50 additions & 6 deletions project_task_subtask/static/src/js/one2many_renderer.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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({
Expand Down
10 changes: 10 additions & 0 deletions project_task_subtask/static/src/xml/templates.xml
@@ -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>
2 changes: 1 addition & 1 deletion project_task_subtask/views/project_task_subtask.xml
Expand Up @@ -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"/>
Expand Down

0 comments on commit c3758b5

Please sign in to comment.