Fix delete urls
This commit is contained in:
parent
fcb31bdd10
commit
e17a4bf627
5 changed files with 10 additions and 26 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gofrs/uuid"
|
|
||||||
"gopkg.in/mgo.v2"
|
"gopkg.in/mgo.v2"
|
||||||
"gopkg.in/mgo.v2/bson"
|
"gopkg.in/mgo.v2/bson"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -95,19 +94,6 @@ func readSpaceurl() []SpaceUrl {
|
||||||
c := session.DB(config.MongoDbDatabase).C("spaceurl")
|
c := session.DB(config.MongoDbDatabase).C("spaceurl")
|
||||||
result := []SpaceUrl{}
|
result := []SpaceUrl{}
|
||||||
c.Find(bson.M{}).Iter().All(&result)
|
c.Find(bson.M{}).Iter().All(&result)
|
||||||
|
|
||||||
for _, spaceUrl := range result {
|
|
||||||
if spaceUrl.Id == "" {
|
|
||||||
generatedUuid, err := uuid.NewV4()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("%v", err)
|
|
||||||
}
|
|
||||||
spaceUrl.Id = generatedUuid.String()
|
|
||||||
updateSpaceurl(spaceUrl)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ class SpaceApiInput extends React.Component {
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.end((err) => {
|
.end((err) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
this.spaceApiInput.input.value = '';
|
this.spaceApiInput.value = '';
|
||||||
this.setState({ open: true });
|
this.setState({ open: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -78,16 +78,16 @@ class SpaceApiInput extends React.Component {
|
||||||
</p>
|
</p>
|
||||||
<div style={style.formContainer}>
|
<div style={style.formContainer}>
|
||||||
<TextField
|
<TextField
|
||||||
hintText={'https://example.com/yourspaceapi.json'}
|
placeholder={'https://example.com/yourspaceapi.json'}
|
||||||
name={'spaceapi-input'}
|
name={'spaceapi-input'}
|
||||||
onChange={this.handleInputChange}
|
onChange={this.handleInputChange}
|
||||||
ref={ref => (this.spaceApiInput = ref)}
|
inputRef={ref => (this.spaceApiInput = ref)}
|
||||||
style={{ width: '100%', maxWidth: '340px' }}
|
style={{ width: '100%', maxWidth: '340px' }}
|
||||||
/>
|
/>
|
||||||
<FloatingActionButton
|
<FloatingActionButton
|
||||||
style={{ marginLeft: '20px' }}
|
style={{ marginLeft: '20px' }}
|
||||||
mini
|
mini
|
||||||
onTouchTap={this.handleButtonClick}
|
onClick={this.handleButtonClick}
|
||||||
>
|
>
|
||||||
<ContentAdd />
|
<ContentAdd />
|
||||||
</FloatingActionButton>
|
</FloatingActionButton>
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ export class UrlList extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
deleteSpaceUrl = (spaceUrl) => {
|
deleteSpaceUrl = (spaceUrl) => {
|
||||||
this.props.deleteSpaceUrl(spaceUrl.url, this.state.secret);
|
this.props.deleteSpaceUrl(spaceUrl.id, this.state.secret);
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,6 @@ export const actions = {
|
||||||
fetchCalendars,
|
fetchCalendars,
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatDate = date => (date.format('DD.MM.YYYY'));
|
|
||||||
const formatTime = date => (date.format('HH:mm'));
|
|
||||||
|
|
||||||
export default handleActions({
|
export default handleActions({
|
||||||
[CALENDARS_FETCHED]: (state, { payload }) => {
|
[CALENDARS_FETCHED]: (state, { payload }) => {
|
||||||
const items = flatten(flatten(
|
const items = flatten(flatten(
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { createAction, handleActions } from 'redux-actions';
|
||||||
import config from '../../api/config';
|
import config from '../../api/config';
|
||||||
|
|
||||||
export const itemStruct = PropTypes.shape({
|
export const itemStruct = PropTypes.shape({
|
||||||
|
id: PropTypes.string.isRequired,
|
||||||
url: PropTypes.string.isRequired,
|
url: PropTypes.string.isRequired,
|
||||||
validated: PropTypes.bool.isRequired,
|
validated: PropTypes.bool.isRequired,
|
||||||
lastUpdated: PropTypes.number.isRequired,
|
lastUpdated: PropTypes.number.isRequired,
|
||||||
|
|
@ -47,14 +48,14 @@ export const validateSpaceUrl = (spaceUrl, secret) => (dispatch) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteSpaceUrl = (spaceUrl, secret) => (dispatch) => {
|
export const deleteSpaceUrl = (spaceUrlId, secret) => (dispatch) => {
|
||||||
request
|
request
|
||||||
.delete(`${config.api.url}/urls/spaceUrl/${secret}`)
|
.delete(`${config.api.url}/urls/${spaceUrlId}/${secret}`)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.end(
|
.end(
|
||||||
(err) => {
|
(err) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
dispatch(deleteSpace(spaceUrl));
|
dispatch(deleteSpace(spaceUrlId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -83,5 +84,5 @@ export default handleActions({
|
||||||
|
|
||||||
return newState;
|
return newState;
|
||||||
},
|
},
|
||||||
[SPACEURL_DELETE]: (state, { payload }) => state.items.filter(ele => ele.url != payload.url),
|
[SPACEURL_DELETE]: (state, { payload }) => state.items.filter(ele => ele.id !== payload),
|
||||||
}, { items: [] });
|
}, { items: [] });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue