Skip to content

Commit

Permalink
feat: support job count
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng committed Aug 16, 2022
1 parent 1d36c7d commit 0318080
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/controller/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
const {
Controller,
} = require('egg');
const safeGet = require('lodash/get');
const _ = require('lodash');

class HomeController extends Controller {
async index() {
const { ctx, app } = this;
const user = ctx.session.user;
const { appid, callbackUrl } = ctx.app.config.authorize.dingtalkAuth;
const siteConfig = await ctx.model.Config.findOne({ raw: true });
const assetsUrl = safeGet(siteConfig, 'data.site.assetsUrl');
const assetsUrl = _.get(siteConfig, 'data.site.assetsUrl');
ctx.body = await app.render({
dingtalkAuth: {
appid,
Expand All @@ -25,6 +25,7 @@ class HomeController extends Controller {
assetsUrl: assetsUrl || app.config.reliableView.assetsUrl,
version: app.config.pkg.version,
siteConfig: app.config.site,
user: await ctx.service.user.buildUserInfo(),
});
}
}
Expand Down
17 changes: 17 additions & 0 deletions app/service/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const _ = require('lodash');
const Service = require('egg').Service;

module.exports = class BuildService extends Service {
async buildUserInfo() {
const { ctx, app } = this;
const res = _.get(ctx, app.config.admin.userKey);
if (app.config.admin.list.includes(res)) {
return {
isAdmin: true,
};
}
return {};
}
};
5 changes: 5 additions & 0 deletions config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,9 @@ config.site = {
},
};

config.admin = {
userKey: '',
list: [],
};

module.exports = config;
2 changes: 1 addition & 1 deletion view/src/components/BuildsTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class BuildsTabs extends React.Component {
onTabClick={this.handleTabClick}
style={{ height: 'auto' }}
>
<TabPane tab={<FormattedMessage id='sidebar.allbuilds' />} key="">
<TabPane tab={<><FormattedMessage id='sidebar.allbuilds' /> ({allJobName.length})</>} key="">
</TabPane>
{ listItems }
</Tabs>
Expand Down

0 comments on commit 0318080

Please sign in to comment.