/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
require('./lockTools.less');
const React = require('react');
const createClass = require('create-react-class');
const request = require('superagent');
const LockTools = createClass({
getInitialState : function() {
return {
fetching : false,
reviewCount : 0
};
},
componentDidMount : function() {
this.updateReviewCount();
},
updateReviewCount : async function() {
const newCount = await request.get('/admin/lock')
.then((res)=>{return res.body?.count || 'Unknown';});
if(newCount != this.state.reviewCount){
this.setState({
reviewCount : newCount
});
}
},
render : function() {
return
Lock Count
Number of brews currently locked: {this.state.reviewCount}
REFRESH
;
}
});
const LockBrew = createClass({
getInitialState : function() {
return {
brewId : '',
code : 1000,
editMessage : '',
shareMessage : '',
result : {}
};
},
handleChange : function(e, varName) {
const output = {};
output[varName] = e.target.value;
this.setState(output);
},
submit : function(e){
e.preventDefault();
if(!this.state.editMessage) return;
const newLock = {
code : parseInt(this.state.code) || 100,
editMessage : this.state.editMessage,
shareMessage : this.state.shareMessage,
applied : new Date
};
request.post(`/admin/lock/${this.state.brewId}`)
.send(newLock)
.set('Content-Type', 'application/json')
.then((response)=>{
this.setState({ result: response.body });
});
},
renderInput : function (name) {
return this.handleChange(e, name)} autoComplete='off' required/>;
},
renderResult : function(){
return <>
Result:
{Object.keys(this.state.result).map((key, idx)=>{
return
{key}
{this.state.result[key].toString()}
;
})}
>;
},
render : function() {
return
Lock Brew
{this.state.result && this.renderResult()}
Suggestions
Codes
455 - Generic Lock
456 - Copyright issues
457 - Confidential Information Leakage
458 - Sensitive Personal Information
459 - Defamation or Libel
460 - Hate Speech or Discrimination
461 - Illegal Activities
462 - Malware or Phishing
463 - Plagiarism
465 - Misrepresentation
466 - Inappropriate Content
Messages
Edit Message: This is the private message that is ONLY displayed to the authors of the locked brew. This message MUST specify exactly what actions must be taken in order to have the brew unlocked.
Share Message: This is the public message that is displayed to the EVERYONE that attempts to view the locked brew.
;
}
});
const LockTable = createClass({
getDefaultProps : function() {
return {
title : '',
fetchURL : '/admin/locks',
resultName : '',
propertyNames : ['shareId']
};
},
getInitialState : function() {
return {
result : '',
error : '',
searching : false
};
},
clickFn(){
this.setState({ searching: true, error: null });
request.get(this.props.fetchURL)
.then((res)=>this.setState({ result: res.body }))
.catch((err)=>this.setState({ error: err }))
.finally(()=>{
this.setState({ searching: false });
});
},
render : function () {
return <>
{this.props.title}
REFRESH
{this.state.result[this.props.resultName] &&
<>
Total Reviews Waiting: {this.state.result[this.props.resultName].length}
Click a row to copy the Share ID to the clipboard
{this.props.propertyNames.map((name, idx)=>{
return {name} ;
})}
{this.state.result[this.props.resultName].map((result, resultIdx)=>{
return {navigator.clipboard.writeText(result.shareId.toString());}}>
{this.props.propertyNames.map((name, nameIdx)=>{
return
{result[name].toString()}
;
})}
;
})}
>
}
>;
}
});
const LockLookup = createClass({
getDefaultProps : function() {
return {
fetchURL : '/admin/lookup'
};
},
getInitialState : function() {
return {
query : '',
result : '',
error : '',
searching : false
};
},
handleChange(e){
this.setState({ query: e.target.value });
},
clickFn(){
this.setState({ searching: true, error: null });
request.put(`${this.props.fetchURL}/${this.state.query}`)
.then((res)=>this.setState({ result: res.body }))
.catch((err)=>this.setState({ error: err }))
.finally(()=>{
this.setState({ searching: false });
});
},
renderResult : function(){
return <>
Result:
{Object.keys(this.state.result).map((key, idx)=>{
return
{key}
{this.state.result[key].toString()}
;
})}
>;
},
render : function() {
return
{this.props.title}
{this.state.error
&&
{this.state.error.toString()}
}
{this.state.result && this.renderResult()}
;
}
});
module.exports = LockTools;