Skip to content

Commit

Permalink
fix: 1.Switch topnav; 2.N details recycle
Browse files Browse the repository at this point in the history
  • Loading branch information
getrebuild committed Dec 1, 2023
1 parent d59bc49 commit 03a619f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,21 @@ public JSON serialize() {
JSONObject s = (JSONObject) queryed.serialize();

Entity detailEntity = entity.getDetailEntity();
if (detailEntity == null) {
return s;
}
if (detailEntity == null) return s;

// 明细
String detailSql = buildBaseSql(detailEntity)
.append(MetadataHelper.getDetailToMainField(detailEntity).getName())
.append(" = ?")
.toString();
List<Record> detailQueryed = Application.createQueryNoFilter(detailSql).setParameter(1, this.recordId).list();
// v36 多明细
JSONArray detailList = new JSONArray();
for (Record r : detailQueryed) {
detailList.add(r.serialize());
for (Entity de : entity.getDetialEntities()) {
String detailSql = buildBaseSql(de)
.append(MetadataHelper.getDetailToMainField(de).getName())
.append(" = ?")
.toString();
List<Record> detailQueryed = Application.createQueryNoFilter(detailSql).setParameter(1, this.recordId).list();
for (Record r : detailQueryed) {
JSONObject item = (JSONObject) r.serialize();
item.put(RestoreRecordCreator.META_FIELD, de.getName());
detailList.add(item);
}
}
s.put(NAME_DETAILLIST, detailList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,22 @@ private List<Record> conver2Record(JSONObject content, ID recordId) {
Record record = new RestoreRecordCreator(entity, content).create(true);
records.add(record);

// v36 多明细
Entity detailEntity = entity.getDetailEntity();
if (detailList != null && detailEntity != null) {
for (Object o : detailList) {
Record detail = new RestoreRecordCreator(detailEntity, (JSONObject) o).create(true);
JSONObject item = (JSONObject) o;
Entity de = detailEntity;
if (item.containsKey(RestoreRecordCreator.META_FIELD)) {
String _entity = (String) item.remove(RestoreRecordCreator.META_FIELD);
if (!MetadataHelper.containsEntity(_entity)) {
log.warn("Detail entity not longer exists : {}", _entity);
continue;
}
de = MetadataHelper.getEntity(_entity);
}

Record detail = new RestoreRecordCreator(de, item).create(true);
records.add(detail);
}
}
Expand Down
40 changes: 29 additions & 11 deletions src/main/resources/web/assets/js/rb-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See LICENSE and COMMERCIAL in the project root for license information.
/* !!! KEEP IT ES5 COMPATIBLE !!! */

// GA
(function () {
;(function () {
var gaScript = document.createElement('script')
gaScript.src = 'https://www.googletagmanager.com/gtag/js?id=G-ZCZHJPMEG7'
gaScript.async = true
Expand Down Expand Up @@ -180,21 +180,20 @@ $(function () {
})
})

if (window.sessionStorage) {
$('.navbar .navbar-collapse>.navbar-nav a').on('click', function (e) {
sessionStorage.setItem('AppHome._InTab', e.target.href.split('?')[1])
})

var $topNavs = $('.navbar .navbar-collapse>.navbar-nav a')
if ($topNavs.length > 1) {
document.onvisibilitychange = function () {
if (document.visibilityState !== 'visible') return

var tabHome = sessionStorage.getItem('AppHome._InTab')
tabHome &&
$(tabHome.split('&')).each(function () {
var active = $('.navbar .navbar-collapse>.navbar-nav li.active>a').attr('href')
if (active) {
active = active.split('?')[1].split('&')
$(active).each(function () {
var nv = this.split('=')
if (nv[0] === 'n') $.cookie('AppHome.Nav', nv[1], { expires: null })
if (nv[0] === 'd') $.cookie('AppHome.Dash', nv[1], { expires: null })
if (nv[0] === 'n') $.cookie('AppHome.Nav', nv[1], { expires: 30 })
if (nv[0] === 'd') $.cookie('AppHome.Dash', nv[1], { expires: 30 })
})
}
console.log('Switch on visibilityState ...', $.cookie('AppHome.Nav'), $.cookie('AppHome.Dash'))
}
}
Expand Down Expand Up @@ -1119,3 +1118,22 @@ var $pages = function (tp, cp) {
if (end <= tp) pages.push(tp)
return pages
}

// 格式化代码
var $formattedCode = function (c, type) {
if (typeof c === 'object') c = JSON.stringify(c)
if (!window.prettier) return c

try {
// eslint-disable-next-line no-undef
return prettier.format(c, {
parser: type || 'json',
// eslint-disable-next-line no-undef
plugins: prettierPlugins,
printWidth: 10,
})
} catch (err) {
console.log('Cannot format code :', err)
return c
}
}

0 comments on commit 03a619f

Please sign in to comment.