Skip to content

Commit

Permalink
support group
Browse files Browse the repository at this point in the history
  • Loading branch information
夫不 committed Jun 29, 2017
1 parent 7162ff7 commit b00d634
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 26 deletions.
12 changes: 12 additions & 0 deletions js/options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
'use strict';
var reres = angular.module('reres', []);

var groupBy = function (collects, name) {
var ret = {}, key;
collects.forEach(function(elem) {
var key = elem[name];
ret[key] = ret[key] || [];
ret[key].push(elem);
});
return ret;
}

reres.controller('mapListCtrl', function($scope) {
var bg = chrome.extension.getBackgroundPage();

Expand All @@ -18,6 +28,7 @@ reres.controller('mapListCtrl', function($scope) {
}

$scope.maps = bg.ReResMap;
$scope.rules = groupBy(bg.ReResMap, 'group');

//编辑框显示状态
$scope.editDisplay = 'none';
Expand Down Expand Up @@ -77,6 +88,7 @@ reres.controller('mapListCtrl', function($scope) {
if ( $scope.virify() ) {
if ($scope.editType === '添加') {
$scope.maps.push($scope.curRule);
$scope.rules = groupBy($scope.maps, 'group');
} else {

}
Expand Down
11 changes: 11 additions & 0 deletions js/popup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
'use strict';
var reres = angular.module('reres', []);
var groupBy = function (collects, name) {
var ret = {}, key;
collects.forEach(function(elem) {
var key = elem[name];
ret[key] = ret[key] || [];
ret[key].push(elem);
});
return ret;
}

reres.controller('mapListCtrl', function ($scope) {
var bg = chrome.extension.getBackgroundPage();
Expand All @@ -18,6 +27,7 @@ reres.controller('mapListCtrl', function ($scope) {
}

$scope.maps = bg.ReResMap;
$scope.rules = groupBy(bg.ReResMap, 'group');

//编辑框显示状态
$scope.editDisplay = 'none';
Expand Down Expand Up @@ -83,6 +93,7 @@ reres.controller('mapListCtrl', function ($scope) {
if ($scope.virify()) {
if ($scope.editType === '添加') {
$scope.maps.push($scope.curRule);
$scope.rules = groupBy(bg.ReResMap, 'group');
} else {

}
Expand Down
46 changes: 29 additions & 17 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<label for="res">Response:</label>
<input type="text" class="form-control" id="res" ng-model="curRule.res"/>
</div>
<div class="form-group">
<label for="res">Group:</label>
<input type="text" class="form-control" id="res" ng-model="curRule.group"/>
</div>
<!-- <div class="form-group">
<label for="type">Type:</label>
<select ng-model="curRule.type" class="form-control" id="type">
Expand All @@ -42,25 +46,33 @@
</div>-->
<button class="btn-block btn btn-primary" ng-click="saveRule()">保存</button>
</div>
<table class="table table-hover">
<thead>
<tr>
<td>Enable</td>
<td>If URL match</td>
<td>Response</td>
<!--<td>Type</td>-->
<td>Operating</td>
</tr>
</thead>
<table>
<tboby>
<tr ng-repeat="rule in maps track by $index">
<td><input type="checkbox" ng-model="rule.checked"/></td>
<td><div title="{{rule.req}}">{{rule.req}}</div></td>
<td><div title="{{rule.res}}">{{rule.res}}</div></td>
<!--<td>{{rule.type == "file" ? "URL映射" : "目录映射"}}</td>-->
<tr ng-repeat="(group, rulesMap) in rules track by $index">
<td>
<button ng-click="edit(rule)" type="button" class="btn btn-primary btn-xs edit">编辑</button>
<button ng-click="removeUrl(rule)" type="button" class="btn btn-default btn-xs remove">删除</button>
<table class="table table-hover table-bordered">
<thead>
<td>Group</td>
<td>Enable</td>
<td>If URL match</td>
<td>Response</td>
<!--<td>Type</td>-->
<td>Operating</td>
</thead>
<tbody>
<tr ng-repeat="rule in rulesMap track by $index">
<td ng-if="$index === 0" rowspan="{{rulesMap.length}}" style="width: 140px;vertical-align: middle;border-right: 1px solid #ddd;background: #fff;">{{group}}</td>
<td><input type="checkbox" ng-model="rule.checked"/></td>
<td><div title="{{rule.req}}">{{rule.req}}</div></td>
<td><div title="{{rule.res}}">{{rule.res}}</div></td>
<!--<td>{{rule.type == "file" ? "URL映射" : "目录映射"}}</td>-->
<td>
<button ng-click="edit(rule)" type="button" class="btn btn-primary btn-xs edit">编辑</button>
<button ng-click="removeUrl(rule)" type="button" class="btn btn-default btn-xs remove">删除</button>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tboby>
Expand Down
21 changes: 12 additions & 9 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@
</div>-->
<button class="btn-block btn btn-primary" ng-click="saveRule()">保存</button>
</div>
<table class="table table-hover">
<tr ng-repeat="rule in maps track by $index">
<td>
<label title="Responese: {{rule.res}}"><input type="checkbox" ng-model="rule.checked"/> {{rule.req}}</label>
<button ng-click="edit(rule)" type="button" class="btn btn-primary btn-xs edit">编辑</button>
<button ng-click="removeUrl(rule)" type="button" class="btn btn-default btn-xs remove">删除</button>
</td>
</tr>
</table>
<div ng-repeat="(group, rulesMap) in rules track by $index">
<h5 style="text-align: center;font-weight: bold;">[{{group}}]</h5>
<table class="table table-hover">
<tr ng-repeat="rule in rulesMap track by $index">
<td>
<label title="Responese: {{rule.res}}"><input type="checkbox" ng-model="rule.checked"/> {{rule.req}}</label>
<button ng-click="edit(rule)" type="button" class="btn btn-primary btn-xs edit">编辑</button>
<button ng-click="removeUrl(rule)" type="button" class="btn btn-default btn-xs remove">删除</button>
</td>
</tr>
</table>
</div>

</div>
</body>
Expand Down

0 comments on commit b00d634

Please sign in to comment.