Skip to content
Open

Jpro #29

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.classpath
.settings/
bin/
config/

# IntelliJ
.idea
Expand Down
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<node.version>v8.9.1</node.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>1.0.0.Final</quarkus.version>
<quarkus.version>1.2.1.Final</quarkus.version>
<rewrite-servlet.version>3.4.1.Final</rewrite-servlet.version>
<surefire-plugin.version>2.22.0</surefire-plugin.version>
<yarn.version>v1.3.2</yarn.version>
Expand Down Expand Up @@ -84,6 +84,10 @@
<artifactId>quarkus-mailer</artifactId>
<version>${quarkus.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/src/app/components/article-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export default class ArticleEdit extends Component {
}
//if it is an event
let eventInputs = "";
if(this.state.location) {
if(this.state.tag === "events") {
eventInputs = (
<span>
<div className="form-group">
Expand Down
17 changes: 17 additions & 0 deletions src/main/frontend/src/app/components/mobiletags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, {Component} from "react";
import ApiCall from "../services/api-call";
import Tags from "./tags";

export default class MobileTags extends Tags {
render() {
return (
this.state.tags.map((tag, i) => {
let link = "/" + tag.name;
return <li key={i}><a href="#"
onClick={(e) => this.handleLinkClick(e, link)}>{tag.name}</a>
</li>
})
);
}
}

151 changes: 151 additions & 0 deletions src/main/frontend/src/app/components/sponsor-edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import React, {Component} from "react";
import ApiCall from "../services/api-call";

export default class SponsorEdit extends Component {

constructor(props) {
super(props);

this.state = {
sponsor: "",
web_url: "",
logo: null,
image_type: "",
message: null,
preview: null,
};

this.onSubmit = this.onSubmit.bind(this);
// this.goToRegister = this.goToRegister.bind(this);
}

onChange = e => this.setState({[e.target.name]: e.target.value});

onFileChangeHandler = (e) => {
this.setState({
logo: e.target.files[0],
image_type: e.target.files[0].type,
preview: URL.createObjectURL(e.target.files[0])
});
};

componentWillReceiveProps() {
const sponsorId = this.props.routeParams.sponsorId;
if (sponsorId === 'new-sponsor') {
this.setState({
id: null,
sponsor: "",
web_url: "",
logo: null,
image_type: "",
preview: null,
})
} else {
ApiCall.get("/api/sponsor/" + sponsorId)
.then((response) => this.setState(
{
id: response.data.id,
sponsor: response.data.name,
web_url: response.data.url,
preview: "/api/sponsor/logo/" + response.data.id
}
));
}
}

onSubmit(event) {
event.preventDefault();

const formData = new FormData();
if (this.state.id) {
formData.append("id", this.state.id)
}
formData.append("sponsor", this.state.sponsor);
formData.append("web_url", this.state.web_url);
if (this.state.logo) {
formData.append("image_type", this.state.image_type);
formData.append("logo", this.state.logo);
}

if (!(this.state.sponsor && this.state.web_url)) {
this.setState({message: "Please fill all fields."});
} else {
let self = this;
//update sponsor
if (this.state.id) {
ApiCall.put("/api/sponsor", formData)
.then((response) => {
console.log(response.headers);
self.setState({message: "Sponsor with ID: " + this.state.id + " updated!"});
self.props.router.push("/");
})
.catch(function (error) {
// handle error
console.log(error);
self.setState({message: "Ops... nothing happened (check the browser console)." + error.response.status});
});
} else {
//create sponsor
ApiCall.post("/api/sponsor", formData)
.then((response) => {
console.log(response.headers);
self.setState({message: "New Sponsor Created!"});
self.props.router.push("/");
})
.catch(function (error) {
// handle error
console.log(error);
self.setState({message: "Ops... nothing happened (check the browser console)." + error.response.status});
});
}
}
}

render() {

let error = null;

if (this.state.message) {
error = (
<div className="alert alert-danger">
<strong>{this.state.message}</strong>
</div>);
}

return (
<div className="row">
<div className="col-md-12">
<div id="sponsors">
<article>
<h1> Create Sponsor </h1>
{error}
<form onSubmit={this.onSubmit}>
<div className="form-group">
<label htmlFor="title">Name:</label>
<input id="sponsor" type="text" name="sponsor" className="form-control"
value={this.state.sponsor || ""}
onChange={this.onChange}/>
</div>
<div className="form-group">
<label htmlFor="title">URL:</label>
<input id="web_url" name="web_url" type="text"
className="form-control grey-textarea"
value={this.state.web_url || ""}
onChange={this.onChange}/>
</div>
<div className="form-group">
<label htmlFor="topic">Logo image:</label>
<input id="logo" type="file" name="logo" className="form-control"
onChange={this.onFileChangeHandler}/>
<img src={this.state.preview} hidden={this.state.preview === null}
alt={this.state.sponsor}/>
</div>
<input type="submit" value="Save" className="btn btn-primary"/> &nbsp;
</form>
</article>
</div>
</div>
</div>
);
}
}
49 changes: 49 additions & 0 deletions src/main/frontend/src/app/components/sponsor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, {Component} from "react";
import JwtUtil from "../services/jwt-util";

export default class Sponsor extends Component {
constructor(props) {
super(props);
this.hashHistory = this.props.hashHistory;
}

componentDidMount() {
}

handleSponsorEdit(event, id) {
window.scrollTo({
top: 0,
left: 0,
behavior: 'smooth'
});
this.hashHistory.push("/edit-sponsor/" + id);
}

handleSponsorRemove(event, id) {
// this.props.router.push("/remove-sponsor/" + id);
}

render() {
let cursorPointerStyle = {
cursor: "pointer"
};

let editSponsor = JwtUtil.isCurrentUserAdmin() ?
(<span style={cursorPointerStyle}>
<span onClick={(e) => this.handleSponsorEdit(e, this.props.sponsor.id)}><i
className='fa fa-edit'/>Edit</span>
<span onClick={(e) => this.handleSponsorRemove(e, this.props.sponsor.id)}><i
className='fa fa-remove'/>Delete</span>
</span>) : '';

return (
<div className='col-md-2 col-sm-2 col-xs-12'>
<div className='spnsors-logo'>
<a href={this.props.sponsor.url}><img className='img-fluid&quot;'
src={'/api/sponsor/logo/' + this.props.sponsor.id}
alt={this.props.sponsor.name}/></a>
{editSponsor} </div>
</div>
)
}
}
83 changes: 83 additions & 0 deletions src/main/frontend/src/app/components/sponsors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React, {Component} from "react";
import ApiCall from "../services/api-call";
import JwtUtil from "../services/jwt-util";
import Sponsor from "./sponsor";

export default class Sponsors extends Component {
constructor(props) {
super(props);
this.state = {sponsors: []};
this.hashHistory = this.props.hashHistory;
}

loadSingleSponsorById = (id) => {
ApiCall.get("/api/sponsor/" + id)
.then((response) => this.setState(
{
sponsors: [response.data]
}
));
};

loadSponsors = () => {
ApiCall.get("/api/sponsor")
.then((response) => this.setState(
{
sponsors: response.data
}
));
};

componentWillMount() {
this.loadSponsors();
}

handlerSponsorAdd(event) {
window.scrollTo({
top: 0,
left: 0,
behavior: 'smooth'
});
this.hashHistory.push("/add-sponsor/new-sponsor");
}

render() {
let cursorPointerStyle = {
cursor: "pointer"
};

let sponsors = this.state.sponsors.map((sponsor, i) => {
return <Sponsor key={i} sponsor={sponsor} hashHistory={this.hashHistory}
loadSponsors={this.loadSponsors}/>
});

let idx = 0;
let sponsor_rows = [];
let i;
for (i = 0; i < sponsors.length; i += 5) {
sponsor_rows[idx++] = <div className="row mb-30">
{sponsors.slice(i, Math.max(i + 5, sponsors.length))}
</div>
}

return (
<div>
{JwtUtil.isCurrentUserAdmin() ?
<article>
<div className='blog-item-wrap'>
<div className='post-add'><span style={cursorPointerStyle}
onClick={(e) => this.handlerSponsorAdd(e)}><i
className='fa fa-plus'/>Add Sponsor</span></div>
</div>
</article> : ''
}
<div className="row">
<div className="col-md-12">
<h1 className="section-sub text-center">Our Sponsors</h1>
</div>
</div>
{sponsor_rows}
</div>
)
}
}
2 changes: 1 addition & 1 deletion src/main/frontend/src/app/components/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class Tags extends Component {
// })};
}

componentWillMount() {
componentDidMount() {
let self = this;
let articles = ApiCall.get("/api/tag")
.then((response) => this.setState({tags: response.data}))
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/src/app/services/api-call.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class ApiCall {

static getRestUrl() {
if (!baseUrl) {
baseUrl = "http://localhost:8080";
baseUrl = window.location.origin;
}

return baseUrl;
Expand Down
Loading