Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev

This commit is contained in:
suxiaoxin 2017-09-27 16:15:13 +08:00
commit 8b036dff69
9 changed files with 74 additions and 28 deletions

View File

@ -58,7 +58,6 @@ function timeago(timestamp) {
@connect(
state => {
console.log(11);
return {
newsData: state.news.newsData,
curpage: state.news.curpage,
@ -98,7 +97,7 @@ class TimeTree extends Component {
if (this.props.curpage <= this.props.newsData.total) {
this.setState({ loading: true });
this.props.fetchMoreNews(this.props.typeid, this.props.type, this.props.curpage+1, 8).then(function () {
this.props.fetchMoreNews(this.props.typeid, this.props.type, this.props.curpage+1, 10).then(function () {
that.setState({ loading: false });
if (that.props.newsData.total === that.props.curpage) {
that.setState({ bidden: "logbidden" })
@ -108,7 +107,7 @@ class TimeTree extends Component {
}
componentWillMount() {
this.props.fetchNewsData(this.props.typeid, this.props.type, 1, 8)
this.props.fetchNewsData(this.props.typeid, this.props.type, 1, 10)
}
render() {
let data = this.props.newsData ? this.props.newsData.list : [];
@ -121,7 +120,6 @@ class TimeTree extends Component {
other: "其他"
};
if (data && data.length) {
console.log(data);
data = data.map(function (item, i) {
return (<Timeline.Item dot={<Link to={`/user/profile/${item.uid}`}><Avatar src={`/api/user/avatar?uid=${item.uid}`} /></Link>} key={i}>
<div className="logMesHeade">

View File

@ -12,9 +12,11 @@ const TabPane = Tabs.TabPane;
import { fetchNewsData } from '../../reducer/modules/news.js';
import './Group.scss';
@connect(
state => {
return {
curGroupId: state.group.currGroup._id,
curUserRole: state.group.currGroup.role,
currGroup: state.group.currGroup
}
},
@ -29,15 +31,15 @@ export default class Group extends Component {
static propTypes = {
fetchNewsData: PropTypes.func,
curGroupId: PropTypes.number,
curUserRole: PropTypes.string,
currGroup: PropTypes.object
}
onTabClick(key){
if(key == 3){
this.props.fetchNewsData(this.props.curGroupId, "group", 1, 8)
this.props.fetchNewsData(this.props.curGroupId, "group", 1, 10)
}
}
render () {
console.log(this.props.currGroup)
const GroupContent = (
<Layout style={{minHeight: 'calc(100vh - 100px)', marginLeft: '24px', marginTop: '24px'}}>
<Sider style={{ height: '100%' }} width={300}>
@ -48,10 +50,8 @@ export default class Group extends Component {
<Content style={{ height: '100%', margin: '0 24px 0 16px', overflow: 'initial',backgroundColor: '#fff'}}>
<Tabs onTabClick={this.onTabClick.bind(this)} type="card" className="m-tab" style={{height: '100%'}}>
<TabPane tab="项目列表" key="1"><ProjectList/></TabPane>
{
this.props.currGroup.type === 'public'?<TabPane tab="成员列表" key="2"><MemberList/></TabPane>:null
}
<TabPane tab="分组动态" key="3"><GroupLog/></TabPane>
{this.props.currGroup.type === 'public'?<TabPane tab="成员列表" key="2"><MemberList/></TabPane>:null}
{["admin","owner","guest","dev"].indexOf(this.props.curUserRole)>-1?<TabPane tab="分组动态" key="3"><GroupLog/></TabPane>:""}
</Tabs>
</Content>
</Layout>

View File

@ -4,3 +4,7 @@
@include row-width-limit;
margin: 0 auto .24rem;
}
.news-box .news-timeline .ant-timeline-item .ant-timeline-item-content{
min-width: 300px !important;
width: 75% !important;
}

View File

@ -125,7 +125,7 @@ export default class GroupList extends Component {
await this.props.fetchGroupList();
this.setState({ groupList: this.props.groupList });
this.props.setCurrGroup(res.data.data)
this.props.fetchNewsData(this.props.currGroup._id, "group", 1, 8)
this.props.fetchNewsData(this.props.currGroup._id, "group", 1, 10)
} else {
message.error(res.data.errmsg)
}
@ -144,7 +144,7 @@ export default class GroupList extends Component {
await this.props.fetchGroupList();
this.setState({ groupList: this.props.groupList });
this.props.setCurrGroup({ group_name, group_desc, _id: id });
this.props.fetchNewsData(this.props.currGroup._id, "group", 1, 8)
this.props.fetchNewsData(this.props.currGroup._id, "group", 1, 10)
}
}
@autobind
@ -170,7 +170,7 @@ export default class GroupList extends Component {
const currGroup = this.props.groupList.find((group) => { return +group._id === +groupId });
this.props.setCurrGroup(currGroup);
this.props.history.replace(`${currGroup._id}`);
this.props.fetchNewsData(groupId, "group", 1, 8)
this.props.fetchNewsData(groupId, "group", 1, 10)
}
@autobind

View File

@ -99,7 +99,10 @@ class ProjectList extends Component {
}
render() {
const projectData = this.state.projectData;
let projectData = this.state.projectData;
projectData = projectData.sort((a,b)=>{
return b.up_time - a.up_time;
})
return (
<div style={{ paddingTop: '24px' }} className="m-panel card-panel card-panel-s project-list" >
<Row className="project-list-header">
@ -114,9 +117,7 @@ class ProjectList extends Component {
<Tooltip title="您没有权限,请联系该分组组长或管理员">
<Button type="primary" disabled >添加项目</Button>
</Tooltip>}
</Col>
</Row>
<Row gutter={16}>
{projectData.length ? projectData.map((item, index) => {

View File

@ -166,6 +166,7 @@ class interfaceController extends baseController {
username: username,
typeid: params.project_id
});
this.projectModel.up(params.project_id,{up_time: new Date().getTime()}).then();
//let project = await this.projectModel.getBaseInfo(params.project_id);
// let interfaceUrl = `http://${ctx.request.host}/project/${params.project_id}/interface/api/${result._id}`
// this.sendNotice(params.project_id, {
@ -473,6 +474,7 @@ class interfaceController extends baseController {
typeid: cate.project_id
});
});
this.projectModel.up(interfaceData.project_id,{up_time: new Date().getTime()}).then();
} else {
let cateid = interfaceData.catid;
this.catModel.get(cateid).then((cate) => {
@ -484,6 +486,7 @@ class interfaceController extends baseController {
typeid: cate.project_id
});
});
this.projectModel.up(interfaceData.project_id,{up_time: new Date().getTime()}).then();
}
if (params.switch_notice === true) {
let project = await this.projectModel.getBaseInfo(interfaceData.project_id);
@ -548,7 +551,7 @@ class interfaceController extends baseController {
typeid: cate.project_id
});
})
this.projectModel.up(data.project_id,{up_time: new Date().getTime()}).then();
ctx.body = yapi.commons.resReturn(result);
} catch (err) {

View File

@ -95,6 +95,7 @@ class interfaceColController extends baseController{
username: username,
typeid: params.project_id
});
// this.projectModel.up(params.project_id,{up_time: new Date().getTime()}).then();
ctx.body = yapi.commons.resReturn(result);
}catch(e){
@ -226,7 +227,7 @@ class interfaceColController extends baseController{
typeid: params.project_id
});
});
this.projectModel.up(params.project_id,{up_time: new Date().getTime()}).then();
ctx.body = yapi.commons.resReturn(result);
@ -295,7 +296,7 @@ class interfaceColController extends baseController{
});
});
this.projectModel.up(caseData.project_id,{up_time: new Date().getTime()}).then();
ctx.body = yapi.commons.resReturn(result);
@ -398,6 +399,7 @@ class interfaceColController extends baseController{
username: username,
typeid: colData.project_id
});
ctx.body = yapi.commons.resReturn(result)
}catch(e){
ctx.body = yapi.commons.resReturn(null, 400, e.message)
@ -510,7 +512,7 @@ class interfaceColController extends baseController{
});
});
this.projectModel.up(caseData.project_id,{up_time: new Date().getTime()}).then();
return ctx.body = yapi.commons.resReturn(result);

View File

@ -2,12 +2,14 @@ const logModel = require('../models/log.js');
const yapi = require('../yapi.js');
const baseController = require('./base.js');
const groupModel = require('../models/group');
const projectModel = require('../models/project');
class logController extends baseController {
constructor(ctx) {
super(ctx);
this.Model = yapi.getInst(logModel);
this.groupModel = yapi.getInst(groupModel);
this.projectModel = yapi.getInst(projectModel);
}
/**
@ -35,13 +37,27 @@ class logController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 400, 'type不能为空');
}
try {
let result = await this.Model.listWithPaging(typeid,type, page, limit);
let count = await this.Model.listCount(typeid,type);
if(type === "group"){
let projectList = await this.projectModel.list(typeid);
for(let i in projectList){
projectList[i] = projectList[i]._id;
}
let projectLogList = await this.Model.listWithPagingByGroup(typeid,projectList,page,limit);
let total = await this.Model.listCountByGroup(typeid,projectList);
ctx.body = yapi.commons.resReturn({
list: projectLogList,
total: Math.ceil(total / limit)
});
}else if(type === "project"){
let result = await this.Model.listWithPaging(typeid,type, page, limit);
let count = await this.Model.listCount(typeid,type);
ctx.body = yapi.commons.resReturn({
total: Math.ceil(count / limit),
list: result
});
}
ctx.body = yapi.commons.resReturn({
total: Math.ceil(count / limit),
list: result
});
} catch (err) {
ctx.body = yapi.commons.resReturn(null, 402, err.message);
}

View File

@ -58,13 +58,35 @@ class logModel extends baseModel {
listWithPaging(typeid,type, page, limit) {
page = parseInt(page);
limit = parseInt(limit);
return this.model.find({
type: type,
typeid: typeid
}).sort({add_time:-1}).skip((page - 1) * limit).limit(limit).exec();
}
listWithPagingByGroup(typeid, pidList, page, limit) {
page = parseInt(page);
limit = parseInt(limit);
return this.model.find({
"$or":[{
type: "project",
typeid: {"$in": pidList}
},{
type: "group",
typeid: typeid
}]
}).sort({add_time:-1}).skip((page - 1) * limit).limit(limit).exec();
}
listCountByGroup(typeid,pidList) {
return this.model.count({
"$or":[{
type: "project",
typeid: {"$in": pidList}
},{
type: "group",
typeid: typeid
}]
});
}
listCount(typeid,type) {
return this.model.count({
typeid: typeid,