Created
November 25, 2015 18:14
-
-
Save mario-chaves/47a170631ca19fe11fbf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
/** | |
* @ngdoc function | |
* @name app.controller:CategorymatchCtrl | |
* @description | |
* # CategorymatchCtrl | |
* Controller of the app | |
*/ | |
function CategoryMatch(SellerService, LoadingService) { | |
var self = this; | |
self.sellerList = function () { | |
LoadingService.startLoading(); | |
SellerService.list().then( | |
function (data) { | |
LoadingService.stopLoading(); | |
self.sellers = data.results; | |
} | |
).catch( | |
function (data) { | |
LoadingService.stopLoading(); | |
self.message = 'Ops.: Error'; | |
console.log(data); | |
} | |
); | |
}; | |
self.sellerList(); | |
self.selectSeller = function (obj) { | |
self.sellerSellected = obj; | |
}; | |
self.selectCategory = function (obj) { | |
self.categorySelected = obj; | |
}; | |
self.selectHubTrue = function (row) { | |
angular.forEach(row.marketplace, function(obj){ | |
if (obj.hub) { | |
self.categorySelected = obj; | |
} | |
}); | |
}; | |
self.data = [ | |
{ | |
seller: {id: 3, category: {id: 123, name: 'test123', parent: {id: 548, name: 't123'}}}, | |
marketplace: [ | |
{'category': {id: 876, name: 'test876', parent: {id: 345, name: 'tt345'}}, hub: false}, | |
{'category': {id: 657, name: 'test657', parent: {id: 324, name: 'tt324'}}, hub: true}, | |
{'category': {id: 453, name: 'test453', parent: null}, hub: false} | |
] | |
}, | |
{ | |
seller: {id: 3, category: {id: 456, name: 'test456', parent: {id: 678, name: 't678'}}}, | |
marketplace: null | |
}, | |
{ | |
seller: {id: 3, category: {id: 887, name: 'test887', parent: {id: 445, name: 't445'}}}, | |
marketplace: [ | |
{'category': {id: 987, name: 'test987', parent: {id: 665, name: 'tt665'}}, hub: false}, | |
{'category': {id: 980, name: 'test980', parent: {id: 556, name: 'tt556'}}, hub: false} | |
] | |
} | |
]; | |
// Payload to send on click in apply button | |
self.payload = { | |
seller: {id: 3, category: {id: 123, name: 'test123', parent: {id: 548, name: 't123'}}}, | |
marketplace: {'category': {id: 876, name: 'test876', parent: {id: 345, name: 'tt345'}}, hub: false} | |
} | |
} | |
angular | |
.module('app') | |
.controller('CategoryMatch', CategoryMatch); | |
CategoryMatch.$inject = ['SellerService', 'LoadingService']; | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="mui-row"> | |
<div class="mui-col-md-12"> | |
<table class="mui-table" ng-init="self.init()"> | |
<thead> | |
<tr> | |
<th>Categoria</th> | |
<th>Sugestão de mapeamento no Marketplace</th> | |
<th class="mui--text-right">Ação</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr ng-repeat="row in self.data" | |
ng-class="{'labs-light-green': self.categorySelected.hub, 'labs-light-yellow': !row.marketplace}"> | |
<td> | |
<span ng-if="row.seller.category.parent"> | |
<strong ng-bind="'[' + row.seller.category.parent.id + ']'"></strong> | |
<span ng-bind="row.seller.category.parent.name"></span> → | |
</span> | |
<strong ng-bind="'[' + row.seller.category.id + ']'"></strong> | |
<span ng-bind="row.seller.category.name"></span> | |
</td> | |
<td> | |
<!-- Sem match --> | |
<span class="mui--text-black-54" ng-if="!row.marketplace">N/A</span> | |
<!-- Category do match --> | |
<div class="mui-dropdown" ng-if="row.marketplace"> | |
<button class="mui-btn mui-btn--primary" data-mui-toggle="dropdown"> | |
<span ng-if="self.categorySelected.category.parent" | |
ng-bind="'[' + self.categorySelected.category.parent.id + '] ' + | |
self.categorySelected.category.name + ' →'"></span> | |
<span ng-bind="'[' + self.categorySelected.category.id + '] ' + | |
self.categorySelected.category.name"></span> | |
<span class="mui-caret"></span> | |
</button> | |
<ul class="mui-dropdown__menu" ng-init="self.selectHubTrue(row)"> | |
<li ng-repeat="item in row.marketplace"> | |
<a href ng-click="self.selectCategory(item)"> | |
<span ng-if="item.category.parent" | |
ng-bind="'[' + item.category.parent.id + '] ' + item.category.parent.name + | |
' →'"></span> | |
<span ng-bind="'[' + item.category.id + '] ' + item.category.name"></span> | |
</a> | |
</li> | |
</ul> | |
</div> | |
</td> | |
<td class="mui--text-right"> | |
<button ng-disabled="self.categorySelected.hub" | |
class="mui-btn mui-btn--small mui-btn--primary">Aplicar</button> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment