diff --git a/src/webparts/summaryWebPart/components/SummaryContainer/SummaryContainer.tsx b/src/webparts/summaryWebPart/components/SummaryContainer/SummaryContainer.tsx index a1b2919..ce4bc8d 100644 --- a/src/webparts/summaryWebPart/components/SummaryContainer/SummaryContainer.tsx +++ b/src/webparts/summaryWebPart/components/SummaryContainer/SummaryContainer.tsx @@ -68,12 +68,13 @@ export default class SummaryContainer extends React.Component { res.forEach(e=>{ - let fieldValue = !e.fieldName.match(/\/Title/gi)?currentProject[0][e.fieldName] : currentProject[0][e.fieldName.split('/')[0]]? currentProject[0][e.fieldName.split('/')[0]]['Title'] : '' - if (fieldValue){ + let fieldValue = !e.fieldName.match(/\/Title/gi)?currentProject[0][e.fieldName] : currentProject[0][e.fieldName.split('/')[0]]? currentProject[0][e.fieldName.split('/')[0]]['Title'] : ''; + + if (fieldValue || typeof fieldValue === 'boolean'){ toState.push({ key: e.key, fieldName: e.fieldRuTitle, - value: fieldValue + value: fieldValue === true ? 'Да' : fieldValue === false ? 'Нет' : fieldValue }); } }); diff --git a/src/webparts/summaryWebPart/components/SummaryWebPart.tsx b/src/webparts/summaryWebPart/components/SummaryWebPart.tsx index 7752132..82599ad 100644 --- a/src/webparts/summaryWebPart/components/SummaryWebPart.tsx +++ b/src/webparts/summaryWebPart/components/SummaryWebPart.tsx @@ -4,24 +4,32 @@ import { Spinner, SpinnerSize } from 'office-ui-fabric-react/lib/Spinner'; import SummaryGlobalComponent from './SummaryGlobalComponent/SummaryGlobalComponent' import { PrimaryButton } from 'office-ui-fabric-react'; import { IPageData } from '../interfaces/IPageData'; +import {sp, Web} from '@pnp/sp' export interface IComponentState{ pageData: IPageData | null isLoaded: boolean; isBlank: boolean; + prjID: string | number; } export default class SummaryWebPart extends React.Component { public state = { pageData: null, isLoaded: false, - isBlank: false + isBlank: false, + prjID: '' } componentDidMount(){ const {requestUrl,context} = this.props; let relUrl = context.pageContext.web.serverRelativeUrl let projectCode = relUrl ? relUrl.split('/')[relUrl.split('/').length - 1] : ''; + + let web = new Web('http://portal.vertex.spb.ru/PMIS'); + web.lists.getById('eeba7db6-4c28-41a2-a54e-82a2aaf0ca15').items.filter("Code_project eq '" + projectCode +"'").select('ID').get().then(e=>{ + this.setState({prjID: e[0].ID}) + }) fetch(requestUrl + /* 'test01_test02_001' */projectCode) .then((response)=>{ @@ -32,8 +40,8 @@ export default class SummaryWebPart extends React.Component { - const { pageData } = this.state; - location.href = 'http://portal.vertex.spb.ru/PMIS/SitePages/EditForm.aspx?itemId=' + pageData.PrjInfo.spID; + const { prjID } = this.state; + location.href = 'http://portal.vertex.spb.ru/PMIS/SitePages/EditForm.aspx?itemId=' + prjID; } public render(): React.ReactElement { diff --git a/src/webparts/summaryWebPart/components/TrafficLight/TrafficLight.tsx b/src/webparts/summaryWebPart/components/TrafficLight/TrafficLight.tsx index fcd3ee0..09ed428 100644 --- a/src/webparts/summaryWebPart/components/TrafficLight/TrafficLight.tsx +++ b/src/webparts/summaryWebPart/components/TrafficLight/TrafficLight.tsx @@ -7,7 +7,7 @@ import { DetailsList, SelectionMode, DetailsListLayoutMode } from 'office-ui-fab export interface IComponentProps{ statuses: {[key: string]: string;}; taskStats: {[key: string]: number;}; - dateInfo: { dateFinish: string, dateStart: string }; + dateInfo: { dateFinish: string, dateStart: string, duration?: any, percentCompl?: any }; } export default class TrafficLight extends React.Component { public renderItemColumn = (item, index: number, column) => { @@ -25,48 +25,52 @@ export default class TrafficLight extends React.Component { return {fieldContent}; } } + + public setItems = (statuses) =>{ + let result = []; + let index = 1; + if (statuses.term !== 'none'){ + result.push( + { + key: index, + fieldName: "Статус по сроку", + status: statuses.term + }); + ++index; + } + if (statuses.budget !== 'none') { + result.push( + { + key: index, + fieldName: "Статус по бюджету", + status: statuses.budget + }); + ++index; + } + if (statuses.percCompl !== 'none') { + result.push( + { + key: index, + fieldName: "Статус по % выполнения", + status: statuses.percCompl + }); + } + return result; + } + public render(): React.ReactElement { const { statuses, taskStats, dateInfo} = this.props; let procent = (taskStats.compl/(taskStats.plan + taskStats.compl + taskStats.exec))* 100; let startDate = moment(dateInfo.dateStart).format("DD.MM.YYYY"); let finDate = moment(dateInfo.dateFinish).format("DD.MM.YYYY"); - let totalDays = new moment.duration((new Date(dateInfo.dateFinish ? dateInfo.dateFinish.split('T')[0] : dateInfo.dateFinish) as any) - (new Date(dateInfo.dateStart ? dateInfo.dateStart.split('T')[0] : dateInfo.dateStart) as any)).asDays(); + let totalDays = dateInfo.duration + 'дн.' return (
{ marginTop: 15, marginBottom: 15 }} - >{`Актуальный статус выполнения ${!isNaN(+procent.toFixed(2)) ? procent.toFixed(2) + '%' : ' -' }`}
+ >{`Актуальный статус выполнения ${dateInfo.percentCompl ? dateInfo.percentCompl.toString().match(/\./gi) ? dateInfo.percentCompl.toFixed(2) : dateInfo.percentCompl : ' -'}${dateInfo.percentCompl ? '%' : ''}`} ); }