Commit 7c472991 authored by Internship UKSW 2019's avatar Internship UKSW 2019

Initial commit

parent 2371ffb9
import React, { Component } from 'react';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import PrivateRoute from './PrivateRoute';
import CreateDocumentRoute from './CreateDocumentRoute';
import CreatorDocumentRoute from './CreatorDocumentRoute';
import ApproverDocumentRoute from './ApproverDocumentRoute';
import YourDocumentRoute from './YourDocumentRoute';
import ManageUserRoute from './ManageUserRoute';
import FormLogin from './FormLogin';
......@@ -27,8 +28,8 @@ class App extends Component {
<YourDocumentRoute exact path="/yourdocument" component={YourDocument} />
<ManageUserRoute exact path="/manageuser" component={ManageUser} />
<ManageUserRoute exact path="/formcreateupdaterole" component={FormCreateUpdateRole} />
<CreateDocumentRoute exact path="/formcreatedocument" component={FormCreateDocument} />
<YourDocumentRoute exact path="/formapprover" component={FormApprover} />
<CreatorDocumentRoute exact path="/formcreatedocument" component={FormCreateDocument} />
<ApproverDocumentRoute exact path="/formapprover" component={FormApprover} />
<YourDocumentRoute exact path="/formrevision" component={FormRevision} />
<Route path='*' component={NotFoundPage} />
</Switch>
......
import React from 'react'
import { Redirect, Route } from 'react-router-dom'
const ApproverDocumentRoute = ({ component: Component, ...rest }) => {
return (
<Route
{...rest}
render={
props =>
localStorage.getItem("user") && (
JSON.parse(localStorage.getItem('dataLogin')).user_role[0].includes("Approver") ) ? (
<Component {...props} />
) : (
<Redirect to={{ pathname: '/', state: { from: props.location } }} />
)
}
/>
)
}
export default ApproverDocumentRoute;
\ No newline at end of file
import React from 'react'
import { Redirect, Route } from 'react-router-dom'
const CreateDocumentRoute = ({ component: Component, ...rest }) => {
const CreatorDocumentRoute = ({ component: Component, ...rest }) => {
return (
<Route
{...rest}
......@@ -17,4 +17,4 @@ const CreateDocumentRoute = ({ component: Component, ...rest }) => {
)
}
export default CreateDocumentRoute;
\ No newline at end of file
export default CreatorDocumentRoute;
\ No newline at end of file
......@@ -58,7 +58,7 @@ export class DataTableApprovalDocument extends Component {
table.on("click", "a", function (e) {
e.preventDefault();
let data = table.row($(this).parents("tr")).data();
window.open("http://10.10.86.48:3000/previewdocument?subject=" + data[2], "_blank");
window.open("http://localhost:3000/formapprover?subject=" + data[2], "_self");
})
}
componentWillUnmount = () => {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -15,7 +15,6 @@ class FormCreate extends Component {
page: [true, false, false, false, false],
validPage: [false, false, false],
optionScopes: ["All Department"],
checkedOptionScopes: [false, false, false],
pageScope: false,
pageReference: false,
businessUnit: JSON.parse(localStorage.getItem('dataLogin')).user_dpt[0],//doc
......@@ -41,190 +40,187 @@ class FormCreate extends Component {
};
}
componentDidMount = async () => {
// { department: "Department 1", bu: "Business Unit 1" },
// { department: "Department 2", bu: "Business Unit 2" },
// { department: "Department 3", bu: "Business Unit 3" },
// { department: "Department 4", bu: "Business Unit 4" }
// { code: "SOP-1", subject: "SOP Marketing", type: "SOP", bu: "Marketing" },
// { code: "WI-1", subject: "WI TI", type: "WI", bu: "IT" },
// { code: "Policy-1", subject: "Policy HR", type: "Policy", bu: "HR" }
var self = this;
var parseString = require('xml2js').parseString;
let responseDepartmentList = await axios.get(process.env.REACT_APP_MAIN_APIURL + '/MIP_VN/departmentList', { headers: { 'accept': 'application/xml' } })
let dataDepartmentList;
parseString(responseDepartmentList.data, function (err, result) {
dataDepartmentList = result.Entries.Entry;
})
for (let i = 0; i < dataDepartmentList.length; i++) {
let datarow = [];
datarow.push(dataDepartmentList[i].DepartmentCode[0] + "-" + dataDepartmentList[i].Department[0]);
datarow.push(dataDepartmentList[i].DepartmentCode[0] + "-" + dataDepartmentList[i].Department[0]);
this.state.dataScopes.push(datarow);
}
let responseReferences = await axios.get(process.env.REACT_APP_MAIN_APIURL + '/DocumentManagement/home', { headers: { 'accept': 'application/xml' } });
let dataReferences;
parseString(responseReferences.data, function (err, result) {
dataReferences = result.documentCollection.document;
})
if (dataReferences != undefined) {
for (let i = 0; i < dataReferences.length; i++) {
try {
var self = this;
var parseString = require('xml2js').parseString;
let responseDepartmentList = await axios.get(process.env.REACT_APP_MAIN_APIURL + '/MIP_VN/departmentList', { headers: { 'accept': 'application/xml' } })
let dataDepartmentList;
parseString(responseDepartmentList.data, function (err, result) {
dataDepartmentList = result.Entries.Entry;
})
for (let i = 0; i < dataDepartmentList.length; i++) {
let datarow = [];
datarow.push(dataReferences[i].doc_code[0]);
datarow.push(dataReferences[i].subject[0]);
datarow.push(dataReferences[i].doc_type[0]);
datarow.push(dataReferences[i].usr_dpt[0]);
datarow.push(dataReferences[i].subject[0]);
this.state.dataReferences.push(datarow);
datarow.push(dataDepartmentList[i].DepartmentCode[0] + "-" + dataDepartmentList[i].Department[0]);
datarow.push(dataDepartmentList[i].DepartmentCode[0] + "-" + dataDepartmentList[i].Department[0]);
this.state.dataScopes.push(datarow);
}
}
var tableScope = $('#tableScope').DataTable({
data: this.state.dataScopes,
columns: [
{ title: "Department" },
{ title: "#" }
],
columnDefs: [
{
targets: 0,
render: function (data, type, row) {
return "<a class='text-decoration-none text-dark' href='#'>" + data + "</a>";
}
},
{
className: 'select-checkbox',
orderable: false,
targets: 1,
render: function (data, type, row) {
return "<input type='checkbox' name='listAddScope[]' value='" + data + "'/>";
}
}
],
lengthMenu: [[25, 50, 75, 100], [25, 50, 75, 100]]
})
tableScope.on("change", "input", function (e) {
e.preventDefault();
let data = tableScope.row($(this).parents("tr")).data();
if (e.target.checked) {
self.state.copyScopes.push(e.target.value);
self.state.validAddScope = true;
} else {
let i = self.state.copyScopes.indexOf(e.target.value);
self.state.copyScopes.splice(i, 1);
if (self.state.copyScopes.length == 0) {
self.state.validAddScope = false;
let responseReferences = await axios.get(process.env.REACT_APP_MAIN_APIURL + '/DocumentManagement/home', { headers: { 'accept': 'application/xml' } });
let dataReferences;
parseString(responseReferences.data, function (err, result) {
dataReferences = result.documentCollection.document;
})
if (dataReferences != undefined) {
for (let i = 0; i < dataReferences.length; i++) {
let datarow = [];
datarow.push(dataReferences[i].doc_code[0]);
datarow.push(dataReferences[i].subject[0]);
datarow.push(dataReferences[i].doc_type[0]);
datarow.push(dataReferences[i].usr_dpt[0]);
datarow.push(dataReferences[i].subject[0]);
this.state.dataReferences.push(datarow);
}
}
self.setState({ validAddScope: self.state.validAddScope });
})
tableScope.on("click", "a", function (e) {
e.preventDefault();
let data = tableScope.row($(this).parents("tr")).data();
let listAddScope = document.getElementsByName("listAddScope[]");
for (let i = 0; i < listAddScope.length; i++) {
if (listAddScope[i].value == data[0]) {
if (listAddScope[i].checked) {
listAddScope[i].checked = false;
let j = self.state.copyScopes.indexOf(listAddScope[i].value);
self.state.copyScopes.splice(j, 1);
if (self.state.copyScopes.length == 0) {
self.state.validAddScope = false;
var tableScope = $('#tableScope').DataTable({
data: this.state.dataScopes,
columns: [
{ title: "Department" },
{ title: "#" }
],
columnDefs: [
{
targets: 0,
render: function (data, type, row) {
return "<a class='text-decoration-none text-dark' href='#'>" + data + "</a>";
}
},
{
className: 'select-checkbox',
orderable: false,
targets: 1,
render: function (data, type, row) {
return "<input type='checkbox' name='listAddScope[]' value='" + data + "'/>";
}
} else {
listAddScope[i].checked = true;
self.state.copyScopes.push(listAddScope[i].value);
self.state.validAddScope = true;
}
self.setState({ validAddScope: self.state.validAddScope });
break;
}
}
})
var tableReference = $('#tableReference').DataTable({
data: this.state.dataReferences,
columns: [
{ title: "Code" },
{ title: "Subject" },
{ title: "Type" },
{ title: "Business Process" },
{ title: "#" }
],
columnDefs: [
{
orderable: false,
targets: 0,
render: function (data, type, row) {
return "<a class='text-decoration-none text-dark' href='#'>" + data + "</a>";
}
},
{
orderable: false,
targets: 1,
render: function (data, type, row) {
return "<a class='text-decoration-none text-dark' href='#'>" + data + "</a>";
],
lengthMenu: [[25, 50, 75, 100], [25, 50, 75, 100]]
})
tableScope.on("change", "input", function (e) {
e.preventDefault();
let data = tableScope.row($(this).parents("tr")).data();
if (e.target.checked) {
self.state.copyScopes.push(data[0]);
self.state.validAddScope = true;
} else {
let i = self.state.copyScopes.indexOf(data[0]);
self.state.copyScopes.splice(i, 1);
if (self.state.copyScopes.length == 0) {
self.state.validAddScope = false;
}
},
{
targets: 2,
render: function (data, type, row) {
return "<a class='text-decoration-none text-dark' href='#'>" + data + "</a>";
}
self.setState({ validAddScope: self.state.validAddScope });
})
tableScope.on("click", "a", function (e) {
e.preventDefault();
let data = tableScope.row($(this).parents("tr")).data();
let listAddScope = document.getElementsByName("listAddScope[]");
for (let i = 0; i < listAddScope.length; i++) {
if (listAddScope[i].value == data[0]) {
if (listAddScope[i].checked) {
listAddScope[i].checked = false;
let j = self.state.copyScopes.indexOf(listAddScope[i].value);
self.state.copyScopes.splice(j, 1);
if (self.state.copyScopes.length == 0) {
self.state.validAddScope = false;
}
} else {
listAddScope[i].checked = true;
self.state.copyScopes.push(listAddScope[i].value);
self.state.validAddScope = true;
}
self.setState({ validAddScope: self.state.validAddScope });
break;
}
},
{
orderable: false,
targets: 3,
render: function (data, type, row) {
return "<a class='text-decoration-none text-dark' href='#'>" + data + "</a>";
}
})
var tableReference = $('#tableReference').DataTable({
data: this.state.dataReferences,
columns: [
{ title: "Code" },
{ title: "Subject" },
{ title: "Type" },
{ title: "Business Process" },
{ title: "#" }
],
columnDefs: [
{
orderable: false,
targets: 0,
render: function (data, type, row) {
return "<a class='text-decoration-none text-dark' href='#'>" + data + "</a>";
}
},
{
orderable: false,
targets: 1,
render: function (data, type, row) {
return "<a class='text-decoration-none text-dark' href='#'>" + data + "</a>";
}
},
{
targets: 2,
render: function (data, type, row) {
return "<a class='text-decoration-none text-dark' href='#'>" + data + "</a>";
}
},
{
orderable: false,
targets: 3,
render: function (data, type, row) {
return "<a class='text-decoration-none text-dark' href='#'>" + data + "</a>";
}
},
{
className: 'select-checkbox',
orderable: false,
targets: 4,
render: function (data, type, row) {
return "<input type='checkbox' name='listReference[]' value='" + data + "'/>";
}
}
},
{
className: 'select-checkbox',
orderable: false,
targets: 4,
render: function (data, type, row) {
return "<input type='checkbox' name='listReference[]' value='" + data + "'/>";
],
lengthMenu: [[25, 50, 75, 100], [25, 50, 75, 100]]
})
tableReference.on("change", "input", function (e) {
e.preventDefault();
let data = tableReference.row($(this).parents("tr")).data();
if (e.target.checked) {
self.state.copyReferences.push(e.target.value);
self.state.validAddReference = true;
} else {
let i = self.state.copyReferences.indexOf(e.target.value);
self.state.copyReferences.splice(i, 1);
if (self.state.copyReferences.length == 0) {
self.state.validAddReference = false;
}
}
],
lengthMenu: [[25, 50, 75, 100], [25, 50, 75, 100]]
})
tableReference.on("change", "input", function (e) {
e.preventDefault();
let data = tableReference.row($(this).parents("tr")).data();
if (e.target.checked) {
self.state.copyReferences.push(e.target.value);
self.state.validAddReference = true;
} else {
let i = self.state.copyReferences.indexOf(e.target.value);
self.state.copyReferences.splice(i, 1);
if (self.state.copyReferences.length == 0) {
self.state.validAddReference = false;
}
}
self.setState({ validAddReference: self.state.validAddReference });
})
tableReference.on("click", "a", function (e) {
e.preventDefault();
let data = tableReference.row($(this).parents("tr")).data();
let listReference = document.getElementsByName("listReference[]");
for (let i = 0; i < listReference.length; i++) {
if (listReference[i].value == data[1]) {
if (listReference[i].checked) {
listReference[i].checked = false;
let j = self.state.copyReferences.indexOf(listReference[i].value);
self.state.copyReferences.splice(j, 1);
if (self.state.copyReferences.length == 0) {
self.state.validAddReference = false;
self.setState({ validAddReference: self.state.validAddReference });
})
tableReference.on("click", "a", function (e) {
e.preventDefault();
let data = tableReference.row($(this).parents("tr")).data();
let listReference = document.getElementsByName("listReference[]");
for (let i = 0; i < listReference.length; i++) {
if (listReference[i].value == data[1]) {
if (listReference[i].checked) {
listReference[i].checked = false;
let j = self.state.copyReferences.indexOf(listReference[i].value);
self.state.copyReferences.splice(j, 1);
if (self.state.copyReferences.length == 0) {
self.state.validAddReference = false;
}
} else {
listReference[i].checked = true;
self.state.copyReferences.push(listReference[i].value);
self.state.validAddReference = true;
}
} else {
listReference[i].checked = true;
self.state.copyReferences.push(listReference[i].value);
self.state.validAddReference = true;
self.setState({ validAddReference: self.state.validAddReference });
break;
}
self.setState({ validAddReference: self.state.validAddReference });
break;
}
}
})
})
} catch (err) {
console.log(err + "");
}
}
sortTable = (idTabel, n) => {
var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
......@@ -727,7 +723,7 @@ class FormCreate extends Component {
"rev_code": this.state.revisionCode,
"remark": null,
"user_id": user_id,
"status": "Waiting for Approval"
"status": "Waiting for Approval - " + dataApprover[0].EmpFullName[0]
}
let postDataRevision = js2xmlparser.parse("_postrevisioninsert", dataRevision);
//Insert Data Revision
......@@ -748,7 +744,12 @@ class FormCreate extends Component {
"subject": "New Approval Request Document",
"name": dataApprover[0].EmpFullName[0],
"email": dataApprover[0].EMail[0],
"message": "Hello " + dataApprover[0].EmpFullName[0] + ", you have new request for approve a document. Please check your account document management."
"message": "<p>Dengan hormat,</p><br /> \
<p>Terdapat pengajuan dokumen dengan No." + this.state.businessUnit + "-" + this.state.documentType + "-" + this.state.revisionCode + " " + this.state.subject + " yang diajukan oleh " + JSON.parse(localStorage.getItem("user"))["Full Name"] + ". Untuk review dan approval silahkan klik link <a href='http://10.10.86.48:3000'>Link_Document</a></p><br /> \
<p>Terimakasih</p> \
<p>Regards</p><br /> \
<p>Admin</p><br /> \
<p><i>Ini adalah email otomatis, harap jangan me-reply ke alamat email ini</i></p>"
}
let responseSendEmail = await fetch(process.env.REACT_APP_MAIN_APIURL + '/email', {
headers: { 'Content-Type': 'application/json' },
......@@ -1212,12 +1213,11 @@ class FormCreate extends Component {
&nbsp;{this.state.labelChangePage[0]}&nbsp;</Button>
</div>
<div className="col-xl-9 col-lg-9 col-md-9 col-sm-9 text-right">
<Button color="primary" onClick={() => this.handleSubmitForm()}>&nbsp;&nbsp;Submit
<Button color="primary" onClick={() => this.handleSubmitForm()}>&nbsp;&nbsp;Submit&nbsp;
{
this.state.submitForm &&
<img src="data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==" />
}&nbsp;&nbsp;&nbsp;</Button>&nbsp;
{/* <input type="submit" value="&nbsp;&nbsp;Submit&nbsp;&nbsp;&nbsp;" className="btn btn-primary" /> */}
}&nbsp;&nbsp;</Button>&nbsp;
</div>
</div>
<div className="container col-xl-12 col-lg-12 col-md-12 col-sm-12 border" id="divToSave">
......
......@@ -302,7 +302,7 @@ class FormCreateUpdateRole extends Component {
<div className="form-group row">
<div className="col-xl-12 col-lg-12 col-md-12 col-sm-12 text-right">
<Button className="button-2 center-block" color="danger" href="/manageuser">Cancel</Button>&nbsp;
<Button className="button-2 center-block" color="success" disabled={!this.state.validFormUser} onClick={() => this.handleSubmitForm()}> {this.handleShowButtonName()}
<Button className="button-2 center-block" color="success" disabled={!this.state.validFormUser} onClick={() => this.handleSubmitForm()}> {this.handleShowButtonName()}&nbsp;
{
this.state.submitForm &&
<img src="data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==" />
......
......@@ -2,6 +2,7 @@ import React, { Component } from 'react';
import { connect } from 'react-redux';
import axios from 'axios';
import Navbar1 from './Navbar';
import ReactLoading from 'react-loading';
import { DataTableHome } from './DataTableHome';
class Home extends Component {
......@@ -13,7 +14,7 @@ class Home extends Component {
}
}
componentDidMount = async () => {
console.log(localStorage.getItem("user"));
console.log(JSON.parse(localStorage.getItem("user")));
try {
let response = await axios.get(process.env.REACT_APP_MAIN_APIURL +'/DocumentManagement/home', { headers: { 'accept': 'application/xml' } });
var parseString = require('xml2js').parseString;
......@@ -56,6 +57,19 @@ class Home extends Component {
return (
<div>
<Navbar1 menu="home" /><br />
{
this.state.fetchStatus == false &&
<div className="container">
<div className="row justify-content-center">
<div className="content-loading">
<div className="form-group row">
<h3 className="text-center">Retrieving Data </h3>
<ReactLoading type="bubbles" color="dark" width="40px" height="20px"></ReactLoading>
</div>
</div>
</div>
</div>
}
{
this.state.fetchStatus == true &&
<div className="container-fluid">
......
......@@ -2,6 +2,7 @@ import React, { Component } from 'react';
import { Button } from 'reactstrap';
import axios from 'axios';
import Navbar1 from './Navbar';
import ReactLoading from 'react-loading';
import './DocumentManagement.css';
import { DataTableManageUser } from './DataTableManageUser';
......@@ -52,7 +53,20 @@ class ManageUser extends Component {
</div>
</div>
{
this.state.fetchStatus == true &&
this.state.fetchStatus == false &&
<div className="container">
<div className="row justify-content-center">
<div className="content-loading">
<div className="form-group row">
<h3 className="text-center">Retrieving Data </h3>
<ReactLoading type="bubbles" color="dark" width="40px" height="20px"></ReactLoading>
</div>
</div>
</div>
</div>
}
{
this.state.fetchStatus == true &&
<DataTableManageUser data={this.state.dataUser}></DataTableManageUser>
}
</div>
......
......@@ -116,7 +116,7 @@ class PreviewDocument extends Component {
return (
<div>
{
this.state.isFetched == false && this.state.isDocumentNotFound == false &&
this.state.isFetched == false && this.state.isDocumentNotFound == false && this.state.isNotValidLocation == false &&
<div className="container">
<div className="row justify-content-center">
<div className="content-loading">
......
......@@ -2,6 +2,7 @@ import React, { Component } from 'react';
import { Button } from 'reactstrap';
import axios from 'axios';
import Navbar1 from './Navbar';
import ReactLoading from 'react-loading';
import { DataTableMyDocument } from './DataTableMyDocument';
import { DataTableApprovalDocument } from './DataTableApprovalDocument';
......@@ -18,57 +19,59 @@ class YourDocument extends Component {
try {
var parseString = require('xml2js').parseString;
let user_id = JSON.parse(localStorage.getItem("dataLogin")).user_id[0];
let responseMyDocument = await axios.get(process.env.REACT_APP_MAIN_APIURL + '/DocumentManagement/mydocument/' + user_id, { headers: { 'accept': 'application/xml' } });
let dataMyDocument;
parseString(responseMyDocument.data, function (err, result) {
dataMyDocument = result.documentCollection.document;
})
if (dataMyDocument != undefined) {
for (let i = 0; i < dataMyDocument.length; i++) {
let datarow = [];
datarow.push("");
datarow.push(dataMyDocument[i].doc_code[0]);
datarow.push(dataMyDocument[i].subject[0]);
datarow.push(dataMyDocument[i].doc_status[0]);
datarow.push(dataMyDocument[i].tracking[0] + " - " + JSON.parse(dataMyDocument[i].approver[0]).EmpFullName);
datarow.push(JSON.parse(localStorage.getItem("user"))["Full Name"])
this.state.dataDocument.push(datarow);
}
}
let responseDataUser = await axios.get(process.env.REACT_APP_MAIN_APIURL + '/DocumentManagement/user', { headers: { 'accept': 'application/xml' } });
let responseDataUser = await axios.get(process.env.REACT_APP_MAIN_APIURL + '/DocumentManagement/user', { headers: { 'accept': 'application/xml' } })
let dataUser;
parseString(responseDataUser.data, function (err, result) {
dataUser = result.user_dataCollection.user_data;
})
let responseApprovalDocument = await axios.get(process.env.REACT_APP_MAIN_APIURL + '/DocumentManagement/approvaldocument', { headers: { 'accept': 'application/xml' } });
let dataApprovalDocument;
parseString(responseApprovalDocument.data, function (err, result) {
dataApprovalDocument = result.documentCollection.document;
let responseAllDocument = await axios.get(process.env.REACT_APP_MAIN_APIURL + '/DocumentManagement/alldocument', { headers: { 'accept': 'application/xml' } })
let dataAllDocument;
parseString(responseAllDocument.data, function (err, result) {
dataAllDocument = result.documentCollection.document;
})
if (dataApprovalDocument != undefined) {
for (let i = 0; i < dataApprovalDocument.length; i++) {
if (JSON.parse(localStorage.getItem("dataProfile")).LoginName == JSON.parse(dataApprovalDocument[i].approver[0]).LoginName) {
let responseDataRevision, dataRevision;
if (dataAllDocument != undefined) {
for (let i = 0; i < dataAllDocument.length; i++) {
responseDataRevision = await axios.get(process.env.REACT_APP_MAIN_APIURL + '/DocumentManagement/revisionkey/' + dataAllDocument[i].doc_id[0], { headers: { 'Content-Type': 'application/xml' } })
dataRevision = responseDataRevision.data.revisionCollection.revision;
if (dataAllDocument[i].user_id[0] == user_id && dataAllDocument[i].doc_status[0] == "New") {
let datarow = [];
let user_name;
for (let j = 0; j < dataUser.length; j++) {
if (dataUser[i].user_id[0] == dataApprovalDocument[i].user_id[0]) {
user_name = dataUser[i].user_name[0];
break;
datarow.push("");
datarow.push(dataAllDocument[i].doc_code[0]);
datarow.push(dataAllDocument[i].subject[0]);
datarow.push(dataAllDocument[i].doc_status[0]);
datarow.push(dataRevision[dataRevision.length - 1].status);
datarow.push(JSON.parse(localStorage.getItem("user"))["Full Name"]);
this.state.dataDocument.push(datarow);
}
if (dataRevision[dataRevision.length - 1].status.includes("Waiting for Approval") && dataAllDocument[i].doc_status[0] == "New") {
if (
(dataRevision[dataRevision.length - 1].status == "Waiting for Approval - Compliance Officer" && JSON.parse(localStorage.getItem('dataLogin')).user_role[0].includes("Compliance Officer")) ||
(dataRevision[dataRevision.length - 1].status == "Waiting for Approval - " + JSON.parse(dataAllDocument[i].approver[0]).EmpFullName && JSON.parse(localStorage.getItem('dataLogin')).user_role[0].includes("Approver") && JSON.parse(localStorage.getItem("dataProfile")).LoginName == JSON.parse(dataAllDocument[i].approver[0]).LoginName) ||
(dataRevision[dataRevision.length - 1].status == "Waiting for Approval - Manager Representative" && JSON.parse(localStorage.getItem('dataLogin')).user_role[0].includes("Manager Representative"))
) {
let datarow2 = [];
let user_name = "";
for (let j = 0; j < dataUser.length; j++) {
if (dataUser[j].user_id[0] == dataAllDocument[i].user_id[0]) {
user_name = dataUser[j].user_name[0];
break;
}
}
datarow2.push("");
datarow2.push(dataAllDocument[i].doc_code[0]);
datarow2.push(dataAllDocument[i].subject[0]);
datarow2.push(dataAllDocument[i].doc_status[0]);
datarow2.push(dataRevision[dataRevision.length - 1].status);
datarow2.push(user_name)
this.state.dataApprovalDocument.push(datarow2);
}
datarow.push("");
datarow.push(dataApprovalDocument[i].doc_code[0]);
datarow.push(dataApprovalDocument[i].subject[0]);
datarow.push(dataApprovalDocument[i].doc_status[0]);
datarow.push(dataApprovalDocument[i].tracking[0] + " - " + JSON.parse(dataApprovalDocument[i].approver[0]).EmpFullName);
datarow.push(user_name)
this.state.dataApprovalDocument.push(datarow);
}
}
}
this.setState({ fetchStatus: true })
await this.setState({ fetchStatus: true });
} catch (error) {
this.setState({ fetchStatus: true })
await this.setState({ fetchStatus: true });
console.log(error + "");
}
}
......@@ -83,6 +86,19 @@ class YourDocument extends Component {
<Button className="center-block" color="primary" href="/formcreatedocument" disabled={!JSON.parse(localStorage.getItem('dataLogin')).user_role[0].includes("Creator")}>Create New Document</Button>
</div>
</div>
{
this.state.fetchStatus == false &&
<div className="container">
<div className="row justify-content-center">
<div className="content-loading">
<div className="form-group row">
<h3 className="text-center">Retrieving Data </h3>
<ReactLoading type="bubbles" color="dark" width="40px" height="20px"></ReactLoading>
</div>
</div>
</div>
</div>
}
{
this.state.fetchStatus == true && JSON.parse(localStorage.getItem('dataLogin')).user_role[0].includes("Creator") &&
<div>
......@@ -95,8 +111,14 @@ class YourDocument extends Component {
</div>
}
{
this.state.fetchStatus == true && JSON.parse(localStorage.getItem('dataLogin')).user_role[0].includes("Approver") &&
this.state.fetchStatus == true &&
(
JSON.parse(localStorage.getItem('dataLogin')).user_role[0].includes("Approver") ||
JSON.parse(localStorage.getItem('dataLogin')).user_role[0].includes("Compliance Officer") ||
JSON.parse(localStorage.getItem('dataLogin')).user_role[0].includes("Manager Representative")
) &&
<div>
<hr />
<div className="form-group row">
<div className="col-xl-12 col-lg-12 col-md-12 col-sm-12">
<h3>Approval Document</h3>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment