Skip to content

Commit

Permalink
💣 Added tree
Browse files Browse the repository at this point in the history
Signed-off-by: Vildan Safin <safin@it-projects.info>
  • Loading branch information
Enigma228322 committed Mar 7, 2020
1 parent eb2907d commit 81e4d1e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 38 deletions.
2 changes: 1 addition & 1 deletion saas_apps/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ def what_dependencies(self, **kw):
if which_price == 'month':
month = True
return {
'dependencies': app.dependencies_info(month)
'dependencies': app.dependencies_info(month, 0)
}
22 changes: 15 additions & 7 deletions saas_apps/models/saas_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,24 @@ def _compute_month_price(self):
for module in self.dependencies:
self.month_price += module.month_price

def dependencies_info(self, for_month):
def dependencies_info(self, for_month, deep):
apps = []
# Root module
if not deep:
apps.append({
'parent': 'root',
'name': self.name,
'price': self.dependencies[0].cost(for_month)
})
# Looking to the period
import wdb
wdb.set_trace()
for app in self.dependencies:
if app.name != self.name:
set = self.search([('name', '=', app.name)])
leafs = set.dependencies_info(for_month)
for app in self.dependencies - self.dependencies[0]:
set = self.search([('name', '=', app.name)])
leafs = set.dependencies_info(for_month, deep + 1)
for leaf in leafs:
if not(leaf in apps):
apps.append(leaf)
item = {
'parent': self.name,
'name': app.name,
'price': app.cost(for_month)
}
Expand Down
57 changes: 27 additions & 30 deletions saas_apps/static/src/js/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ odoo.define('saas_apps.model', function (require){
return -1;
}

// Finding all the links up to the tree,
// and push them to delete_list
delete_list = [];
function leaf_to_root(name){
if(!delete_list.includes(name))
Expand All @@ -29,15 +31,10 @@ odoo.define('saas_apps.model', function (require){
if(roots === undefined)
return;
if(roots.length > 0){
if(typeof(roots) === "string"){
delete_list.push(roots);
leaf_to_root(roots);
}else{
roots.forEach(function(root){
delete_list.push(root);
leaf_to_root(root);
});
}
roots.forEach(function(root){
delete_list.push(root);
leaf_to_root(root);
});
}
}

Expand All @@ -50,11 +47,29 @@ odoo.define('saas_apps.model', function (require){
session.rpc('/what_dependencies', {
args: [e.target.innerText, price_period]
}).then(function (result) {
console.log(result);

/* Be carefull with dependecies when changing programm logic,
cause first dependence - is module himself*/
cause first dependence - is module himself*/
var i = 0, choosing_new = false;
for(; i < result.dependencies.length; ++i){
// Add new element to the dependencies tree, cause we'll restablish a path from leaf to the root
// when we'll have to delete one of leafs
if(i > 0){
modules_parents = tree.get(result.dependencies[i].name);
root_module_name = result.dependencies[i].parent;
leaf_name = result.dependencies[i].name;
if(modules_parents === undefined){
tree.set(leaf_name, [root_module_name]);
console.log("INFO:Added new leaf '"+leaf_name+"' with root module '"+root_module_name+"'.");
}
else if(!modules_parents.includes(root_module_name)){
modules_parents.push(root_module_name);
console.log("INFO:Added new root module '"+root_module_name+"' to leaf '"+leaf_name+"'.");
}
else{
console.log("WARNING:Root module '"+root_module_name+"' already in tree!");
}
}
leaf_name = result.dependencies[i].name;
if(includes_module(leaf_name) === -1)
{
Expand All @@ -63,7 +78,7 @@ odoo.define('saas_apps.model', function (require){
choosing_new = true;
}else{
if(choosing_new)
break;
continue;
leaf_to_root(leaf_name);
delete_list.forEach(function(module){
choosen.splice(includes_module(module), 1);
Expand All @@ -72,24 +87,6 @@ odoo.define('saas_apps.model', function (require){
delete_list = [];
break;
}
// Add new element to the dependencies tree, cause we'll restablish a path from leaf to the root
// when we'll have to delete one of leafs
if(i > 0){
modules_parents = tree.get(result.dependencies[i].name);
root_module_name = result.dependencies[0].name;
leaf_name = result.dependencies[i].name;
if(modules_parents !== "undefined"){
tree.set(leaf_name, root_module_name);
console.log("INFO:Added new leaf '"+leaf_name+"' with root module '"+root_module_name+"'.");
}
else if(!modules_parents.includes(root_module_name)){
modules_parents.push(root_module_name);
console.log("INFO:Added new root module '"+root_module_name+"' to leaf '"+leaf_name+"'.");
}
else{
console.log("WARNING:Root module '"+root_module_name+"' already in tree!");
}
}
}
});
}else if(e.target.className.includes("nav-link") && (e.target.innerText === "Annually" || e.target.innerText === "Monthly")){
Expand Down

0 comments on commit 81e4d1e

Please sign in to comment.