Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete widget backend #38

Merged
merged 2 commits into from
Sep 6, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CogboardConstants {

const val EVENT_SEND_MESSAGE_TO_WEBSOCKET = "cogboard.websocket.message"
const val EVENT_UPDATE_WIDGET_CONFIG = "cogboard.config.widget.update"
const val EVENT_DELETE_WIDGET_CONFIG = "cogboard.config.widget.delete"
const val EVENT_CONFIG_SAVE = "cogboard.config.save"
const val EVENT_HTTP_GET = "cogboard.httpclient.get"
const val EVENT_HTTP_CHECK = "cogboard.httpclient.check"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ConfigManager : AbstractVerticle() {
storage = VolumeStorage(vertx)
listenOnConfigSave()
listenOnWidgetUpdate()
listenOnWidgetDelete()
loadConfig()
}

Expand All @@ -35,6 +36,11 @@ class ConfigManager : AbstractVerticle() {
.consumer<JsonObject>(CogboardConstants.EVENT_UPDATE_WIDGET_CONFIG)
.handler { createOrUpdate(it.body()) }

private fun listenOnWidgetDelete() = vertx
.eventBus()
.consumer<JsonObject>(CogboardConstants.EVENT_DELETE_WIDGET_CONFIG)
.handler { delete(it.body()) }

private fun loadConfig() = storage
.loadConfig()
.getJsonObject(CogboardConstants.PROP_WIDGETS)
Expand All @@ -55,7 +61,17 @@ class ConfigManager : AbstractVerticle() {
attachEndpoint(newConfig)
widgets[id] = WidgetIndex.create(newConfig, vertx).start()
} else {
LOGGER.error("There is widget with no ID in configuration: $config")
LOGGER.error("Widget Update / Create | There is widget with no ID in configuration: $config")
}
}

private fun delete(config: JsonObject) {
val id = config.getString(CogboardConstants.PROP_ID)

if (id != null) {
widgets.remove(id)?.stop()
} else {
LOGGER.error("Widget Delete | There is widget with no ID in configuration: $config")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.cognifide.cogboard.widget.handler

import com.cognifide.cogboard.CogboardConstants
import io.knotx.server.api.handler.RoutingHandlerFactory
import io.vertx.core.Handler
import io.vertx.core.json.JsonObject
import io.vertx.reactivex.core.Vertx
import io.vertx.reactivex.ext.web.RoutingContext

class DeleteWidget : RoutingHandlerFactory {

override fun getName(): String = "widget-delete-handler"

override fun create(vertx: Vertx?, config: JsonObject?): Handler<RoutingContext> = Handler { event ->
vertx
?.eventBus()
?.publish(CogboardConstants.EVENT_DELETE_WIDGET_CONFIG, event.body.toJsonObject())
event
.response()
.end(config?.getJsonObject("body", DEFAULT_NO_BODY)?.encode())
}

companion object {
val DEFAULT_NO_BODY: JsonObject = JsonObject().put("status", "failed")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ com.cognifide.cogboard.config.handler.GetConfig
com.cognifide.cogboard.config.handler.SaveConfig
com.cognifide.cogboard.config.handler.HomePage
com.cognifide.cogboard.widget.handler.UpdateWidget
com.cognifide.cogboard.widget.handler.DeleteWidget
com.cognifide.cogboard.security.LoginHandler
7 changes: 6 additions & 1 deletion cogboard-webapp/src/actions/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ const makeWidgetUpdaterThunk = (beforeUpdateActionCreator, widgetDataCreator) =>
const removeWidgetThunk = (id) =>
(dispatch, getState) => {
const { currentBoard: boardId } = getState().ui;
const token = getState().app.jwToken;

dispatch(deleteWidget(id, boardId));
return fetchData(URL.DELETE_WIDGET, 'POST', { id }, token)
.then(
() => dispatch(deleteWidget(id, boardId)),
console.error
);
};

export const reorderWidgets = (sourceId, targetIndex) =>
Expand Down
1 change: 1 addition & 0 deletions cogboard-webapp/src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const URL = {
LOAD_DATA: '/api/config', // for front dev change to '/data.json'
SAVE_DATA: '/api/config/save',
UPDATE_WIDGET: '/api/widget/update',
DELETE_WIDGET: '/api/widget/delete',
LOGIN: '/api/login'
};
export const COLUMNS_MIN = 1;
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@

### Other
* [Stack](./stack)
* [Tips & Tricks](./tips)
* [Screenshots](./screens)
13 changes: 13 additions & 0 deletions docs/tips.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#### 1. Error while deploying Cogboard container
If You see similar error while deploying Cogboard:
```bash
Failed to deploy 'cogboard Image id: cogboard/cogboard-app': com.github.dockerjava.api.exception.InternalServerErrorException: {"message":"error while creating mount source path '/host_mnt/c/Users/user.name/.workspace/cogboard/mnt': mkdir /host_mnt/c: file exists"
```
If you recently changed your AD password.
##### Try to restart `Docker Desktop` so it will ask You for AD credentials to access local filesystem.

----

#### 2.

----
8 changes: 8 additions & 0 deletions knotx/conf/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ paths:
responses:
default:
description: Widget Update Handler
/api/widget/delete:
post:
operationId: widget-delete-handler
security:
- cogboardAuth: []
responses:
default:
description: Widget Delete Handler
/:
get:
operationId: home-page
Expand Down
14 changes: 14 additions & 0 deletions knotx/conf/routes/operations.conf
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,18 @@ routingOperations = ${routingOperations} [
}
]
}
{
operationId = widget-delete-handler
handlers = [
{
name = widget-delete-handler
config {
body {
status = success
message = "Widget Deleted"
}
}
}
]
}
]