Skip to content

Commit 44de984

Browse files
committed
optimized group edit&fix sync issue
1 parent 54907c1 commit 44de984

4 files changed

Lines changed: 29 additions & 10 deletions

File tree

‎cache.manifest‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CACHE MANIFEST
2-
# Build: 20160118112831
2+
# Build: 20160119092030
33

44
CACHE:
55
resources/fonts/Dressedless_Three.svg

‎index.html‎

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

‎static/app/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ <h5>Add GitHub accounts to group your stars and repos</h5>
153153
<article class="card repo-group-item" data-id="{id}">
154154
<header class="card-header hd" role="tab" id="repo_group_hd_{id}">
155155
<a href="#repo_group_list_{id}" data-toggle="collapse" data-parent=".bd" aria-expanded="false" aria-controls="repo_group_list_{id}">{name}</a>
156-
&nbsp;<span class="label label-info label-pill">{itemCount}</span>
156+
&nbsp;<span class="label label-info label-pill count">{itemCount}</span>
157157
<div class="btn-group btn-group-sm pull-xs-right ctrl">
158158
<button class="btn btn-secondary btn-sm del" data-id="{id}"><i class="fa fa-trash-o"></i></button>
159159
</div>

‎static/app/src/App.js‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ $(function () {
559559
}
560560
ids = ids.length ? ids.join(',') : '';
561561
DB.update(Tables.RepoGroup).set(Tables.RepoGroup.repoIds, ids).where(Tables.RepoGroup.id.eq(id))
562-
.exec().then(function () {
562+
.exec().then(function (res) {
563563
win.trigger('DB:Table.RepoGroup.onchange', {type: DBEventType.U, result: res});
564564
});
565565
}
@@ -668,6 +668,7 @@ $(function () {
668668
}
669669
this.resetPage = function(){
670670
page = 1;
671+
mainData = [];
671672
}
672673
this.request = function (callback) {
673674
$.ajax({
@@ -699,6 +700,7 @@ $(function () {
699700
}
700701
this.resetPage = function(){
701702
page = 1;
703+
mainData = [];
702704
}
703705
this.request = function (callback) {
704706
$.ajax({
@@ -860,7 +862,9 @@ $(function () {
860862

861863
//bookmark
862864
els.win.on('DB:ready', renderBookmarkGroup);
863-
els.win.on('DB:Table.RepoGroup.onchange', renderBookmarkGroup);
865+
els.win.on('DB:Table.RepoGroup.onchange', function(e,data){
866+
data && data.type!='UPDATED' && renderBookmarkGroup();
867+
});
864868
els.bookmarkBtn.on('click', showBookmark);
865869
els.bookmarkModal.on('click', '.add-account', showBookmarkUserModal);
866870
els.bookmarkModal.on('click', '.add-group', showBookmarkGroupModal);
@@ -1393,17 +1397,32 @@ $(function () {
13931397

13941398
function beforeAddRepoToGroup() {
13951399
var el = $(this),
1396-
gId = el.attr('data-id'),
1400+
targetGroupId = el.attr('data-id'),
13971401
repoEl = el.parents('.repo-item'),
13981402
repoId = repoEl.attr('data-repoid'),
13991403
curGroupEl = el.parents('.repo-group-item'),
1400-
curGroupId = curGroupEl.attr('data-id');
1404+
curGroupId = curGroupEl.attr('data-id'),
1405+
curGroupElCountEl = curGroupEl.find('.hd>.count'),
1406+
curGoupCountNum = parseInt(curGroupElCountEl.html()),
1407+
targetGoupEl = curGroupEl.siblings('.repo-group-item[data-id="'+targetGroupId+'"]'),
1408+
targetGoupCountEl = targetGoupEl.find('.hd>.count'),
1409+
targetGoupCountNum = parseInt(targetGoupCountEl.html()),
1410+
targetGroupHasRepo = targetGoupEl.find('.repo-item[data-repoid="'+repoId+'"]').length;
14011411

14021412
els.lastEditBookmarkRepoGroupId = curGroupId;
1403-
if (gId != undefined && gId != 0) {
1404-
bookmarkModel.RepoGroupTable.addRopoId(gId, repoId);
1413+
if (targetGroupId != undefined && targetGroupId != 0) {
1414+
bookmarkModel.RepoGroupTable.addRopoId(targetGroupId, repoId);
1415+
1416+
if(!targetGroupHasRepo){
1417+
targetGoupCountEl.html(++targetGoupCountNum);
1418+
targetGoupEl.find('.repo-list').append(repoEl.clone());
1419+
}
1420+
14051421
} else if (curGroupId != 0) {
14061422
bookmarkModel.RepoGroupTable.removeRopoId(curGroupId, repoId);
1423+
1424+
curGroupElCountEl.html(--curGoupCountNum);
1425+
repoEl.remove();
14071426
}
14081427
}
14091428

0 commit comments

Comments
 (0)