@ -1,10 +1,27 @@
import React from "react" ;
import React from "react" ;
import { Card , Tag , message , Icon , Input , notification , Divider , Button , Spin , Tooltip , Popconfirm , Modal } from "antd" ;
import {
Card ,
Tag ,
message ,
Icon ,
Input ,
notification ,
Divider ,
Button ,
Spin ,
Tooltip ,
Popconfirm ,
Modal ,
Row ,
Col ,
Typography
} from "antd" ;
import axios from "axios" ;
import axios from "axios" ;
import config from "../../../../public/conf/config.json" ;
import config from "../../../../public/conf/config.json" ;
import { TweenOneGroup } from 'rc-tween-one' ;
import { TweenOneGroup } from 'rc-tween-one' ;
import pSBC from "shade-blend-color" ;
import pSBC from "shade-blend-color" ;
const { Title } = Typography ;
class ManageCategories extends React . Component {
class ManageCategories extends React . Component {
state = {
state = {
@ -22,7 +39,7 @@ class ManageCategories extends React.Component {
componentDidMount ( ) {
componentDidMount ( ) {
axios . get (
axios . get (
config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + config . serverConfig . invoker . uri + config . serverConfig . invoker . publisher + "/applications/categories" ,
config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + config . serverConfig . invoker . uri + config . serverConfig . invoker . publisher + "/applications/categories" ,
) . then ( res => {
) . then ( res => {
if ( res . status === 200 ) {
if ( res . status === 200 ) {
let categories = JSON . parse ( res . data . data ) ;
let categories = JSON . parse ( res . data . data ) ;
@ -34,7 +51,7 @@ class ManageCategories extends React.Component {
} ) . catch ( ( error ) => {
} ) . catch ( ( error ) => {
if ( error . hasOwnProperty ( "response" ) && error . response . status === 401 ) {
if ( error . hasOwnProperty ( "response" ) && error . response . status === 401 ) {
window . location . href = config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + '/publisher/login' ;
window . location . href = config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + '/publisher/login' ;
} else {
} else {
message . warning ( 'Something went wrong' ) ;
message . warning ( 'Something went wrong' ) ;
@ -57,8 +74,7 @@ class ManageCategories extends React.Component {
loading : true
loading : true
} ) ;
} ) ;
axios . delete (
axios . delete (
config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + config . serverConfig . invoker . uri + config . serverConfig . invoker . publisher + "/admin/applications/categories/" + id ,
config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + config . serverConfig . invoker . uri + config . serverConfig . invoker . publisher + "/admin/applications/categories/" + id ,
) . then ( res => {
) . then ( res => {
if ( res . status === 200 ) {
if ( res . status === 200 ) {
notification [ "success" ] ( {
notification [ "success" ] ( {
@ -82,9 +98,14 @@ class ManageCategories extends React.Component {
} ) . catch ( ( error ) => {
} ) . catch ( ( error ) => {
if ( error . hasOwnProperty ( "response" ) && error . response . status === 401 ) {
if ( error . hasOwnProperty ( "response" ) && error . response . status === 401 ) {
message . error ( 'You are not logged in' ) ;
message . error ( 'You are not logged in' ) ;
window . location . href = config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + '/publisher/login' ;
window . location . href = config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + '/publisher/login' ;
} else {
} else {
message . warning ( 'Something went wrong when trying to load categories' ) ;
notification [ "error" ] ( {
message : "There was a problem" ,
duration : 0 ,
description :
"Error occurred while trying to load categories." ,
} ) ;
}
}
this . setState ( {
this . setState ( {
loading : false
loading : false
@ -96,7 +117,7 @@ class ManageCategories extends React.Component {
const categoryName = category . categoryName ;
const categoryName = category . categoryName ;
const tagElem = (
const tagElem = (
< Tag
< Tag
color = { pSBC ( 0.30 , config . theme . primaryColor ) }
color = { pSBC ( 0.30 , config . theme . primaryColor ) }
>
>
{ categoryName }
{ categoryName }
< Divider type = "vertical" / >
< Divider type = "vertical" / >
@ -139,7 +160,7 @@ class ManageCategories extends React.Component {
const tagElem = (
const tagElem = (
< Tag
< Tag
closable
closable
onClose = { e => {
onClose = { e => {
e . preventDefault ( ) ;
e . preventDefault ( ) ;
const { tempElements } = this . state ;
const { tempElements } = this . state ;
const remainingElements = tempElements . filter ( function ( value ) {
const remainingElements = tempElements . filter ( function ( value ) {
@ -197,9 +218,8 @@ class ManageCategories extends React.Component {
const data = tempElements . map ( category => category . categoryName ) ;
const data = tempElements . map ( category => category . categoryName ) ;
axios . post (
axios . post (
config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + config . serverConfig . invoker . uri + config . serverConfig . invoker . publisher + "/admin/applications/categories" ,
config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + config . serverConfig . invoker . uri + config . serverConfig . invoker . publisher + "/admin/applications/categories" ,
data ,
data ,
) . then ( res => {
) . then ( res => {
if ( res . status === 200 ) {
if ( res . status === 200 ) {
notification [ "success" ] ( {
notification [ "success" ] ( {
@ -221,9 +241,14 @@ class ManageCategories extends React.Component {
} ) . catch ( ( error ) => {
} ) . catch ( ( error ) => {
if ( error . hasOwnProperty ( "response" ) && error . response . status === 401 ) {
if ( error . hasOwnProperty ( "response" ) && error . response . status === 401 ) {
message . error ( 'You are not logged in' ) ;
message . error ( 'You are not logged in' ) ;
window . location . href = config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + '/publisher/login' ;
window . location . href = config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + '/publisher/login' ;
} else {
} else {
message . warning ( 'Something went wrong when trying to add categories' ) ;
notification [ "error" ] ( {
message : "There was a problem" ,
duration : 0 ,
description :
"Error occurred while trying to add categories." ,
} ) ;
}
}
this . setState ( {
this . setState ( {
loading : false
loading : false
@ -260,9 +285,8 @@ class ManageCategories extends React.Component {
} ) ;
} ) ;
axios . put (
axios . put (
config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + config . serverConfig . invoker . uri + config . serverConfig . invoker . publisher + "/admin/applications/categories/rename?from=" + currentlyEditingId + "&to=" + editingValue ,
config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + config . serverConfig . invoker . uri + config . serverConfig . invoker . publisher + "/admin/applications/categories/rename?from=" + currentlyEditingId + "&to=" + editingValue ,
{ } ,
{ } ,
) . then ( res => {
) . then ( res => {
if ( res . status === 200 ) {
if ( res . status === 200 ) {
notification [ "success" ] ( {
notification [ "success" ] ( {
@ -283,9 +307,14 @@ class ManageCategories extends React.Component {
} ) . catch ( ( error ) => {
} ) . catch ( ( error ) => {
if ( error . hasOwnProperty ( "response" ) && error . response . status === 401 ) {
if ( error . hasOwnProperty ( "response" ) && error . response . status === 401 ) {
message . error ( 'You are not logged in' ) ;
message . error ( 'You are not logged in' ) ;
window . location . href = config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + '/publisher/login' ;
window . location . href = config . serverConfig . protocol + "://" + config . serverConfig . hostname + ':' + config . serverConfig . httpsPort + '/publisher/login' ;
} else {
} else {
message . warning ( 'Something went wrong when trying to delete the category' ) ;
notification [ "error" ] ( {
message : "There was a problem" ,
duration : 0 ,
description :
"Error occurred while trying to delete the category." ,
} ) ;
}
}
this . setState ( {
this . setState ( {
loading : false ,
loading : false ,
@ -308,21 +337,33 @@ class ManageCategories extends React.Component {
const temporaryElements = tempElements . map ( this . renderTempElement ) ;
const temporaryElements = tempElements . map ( this . renderTempElement ) ;
return (
return (
< div style = { { marginBottom : 16 } } >
< div style = { { marginBottom : 16 } } >
< Card title = "Categories" >
< Card >
< Spin tip = "Working on it..." spinning = { this . state . loading } >
< Spin tip = "Working on it..." spinning = { this . state . loading } >
< Row >
< Col span = { 16 } >
< Title level = { 4 } > Categories < / T i t l e >
< / C o l >
< Col span = { 8 } >
{ ! isAddNewVisible &&
{ ! isAddNewVisible &&
< div style = { { float : "right" } } >
< Button
< Button
icon = "plus"
// type="primary"
size = "small"
size = "small"
onClick = { ( ) => {
onClick = { ( ) => {
this . setState ( {
this . setState ( {
isAddNewVisible : true ,
isAddNewVisible : true ,
inputVisible : true
inputVisible : true
} , ( ) => this . input . focus ( ) )
} , ( ) => this . input . focus ( ) )
} } htmlType = "button" > Add Categories
} } htmlType = "button" > Add
< / B u t t o n >
< / B u t t o n >
< / d i v >
}
}
< / C o l >
< / R o w >
{ isAddNewVisible &&
{ isAddNewVisible &&
< div >
< div >
< Divider / >
< div style = { { marginBottom : 16 } } >
< div style = { { marginBottom : 16 } } >
< TweenOneGroup
< TweenOneGroup
enter = { {
enter = { {
@ -360,14 +401,18 @@ class ManageCategories extends React.Component {
< / T w e e n O n e G r o u p >
< / T w e e n O n e G r o u p >
< / d i v >
< / d i v >
< div >
< div >
{ tempElements . length > 0 && (
< span >
< Button
< Button
onClick = { this . handleSave }
onClick = { this . handleSave }
htmlType = "button" type = "primary"
htmlType = "button" type = "primary"
size = "small"
size = "small"
disabled = { tempElements . length === 0 } >
>
Save
Save
< / B u t t o n >
< / B u t t o n >
< Divider type = "vertical" / >
< Divider type = "vertical" / >
< / s p a n >
) }
< Button
< Button
onClick = { this . handleCloseButton }
onClick = { this . handleCloseButton }
size = "small" >
size = "small" >
@ -402,7 +447,8 @@ class ManageCategories extends React.Component {
onCancel = { this . closeEditModal }
onCancel = { this . closeEditModal }
onOk = { this . editItem }
onOk = { this . editItem }
>
>
< Input value = { this . state . editingValue } ref = { ( input ) => this . editingInput = input } onChange = { this . handleEditInputChange } / >
< Input value = { this . state . editingValue } ref = { ( input ) => this . editingInput = input }
onChange = { this . handleEditInputChange } / >
< / M o d a l >
< / M o d a l >
< / d i v >
< / d i v >
) ;
) ;