Update client config after upload, import or index

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer
2019-11-16 23:22:50 +01:00
parent 64868c81b3
commit aebbb17a53
7 changed files with 17 additions and 36 deletions

View File

@@ -1,4 +1,4 @@
import Api from "common/api";
import Event from "pubsub-js";
class Config {
/**
@@ -11,8 +11,7 @@ class Config {
this.values = values;
// this.setValues(JSON.parse(this.storage.getItem(this.storage_key)));
// this.setValues(values);
this.subscriptionId = Event.subscribe('config.updated', (ev, data) => this.setValues(data));
}
setValues(values) {
@@ -52,14 +51,6 @@ class Config {
return this;
}
pullFromServer() {
return Api.get("config").then(
(result) => {
this.setValues(result.data);
}
);
}
}
export default Config;

View File

@@ -27,6 +27,7 @@
</template>
<script>
import Alert from "common/alert";
import Event from "pubsub-js";
export default {
@@ -55,12 +56,12 @@
this.$api.post('import').then(function () {
ctx.busy = false;
ctx.completed = 100;
this.fileName = '';
ctx.fileName = '';
}).catch(function () {
this.$alert.error("Import failed");
Alert.error("Import failed");
ctx.busy = false;
ctx.completed = 0;
this.fileName = '';
ctx.fileName = '';
});
},
handleEvent(ev, data) {

View File

@@ -27,6 +27,7 @@
</template>
<script>
import Alert from "common/alert";
import Event from "pubsub-js";
export default {
@@ -55,12 +56,12 @@
this.$api.post('index').then(function () {
ctx.busy = false;
ctx.completed = 100;
this.fileName = '';
ctx.fileName = '';
}).catch(function () {
this.$alert.error("Indexing failed");
Alert.error("Indexing failed");
ctx.busy = false;
ctx.completed = 0;
this.fileName = '';
ctx.fileName = '';
});
},
handleEvent(ev, data) {

View File

@@ -53,18 +53,4 @@ describe("common/config", () => {
const result = config.getValue("city");
assert.equal(result, "Berlin");
});
it("should pull from server", async() => {
mock.onGet("config").reply(200, {fromServer: "yes"});
const storage = window.localStorage;
const values = {name: "testConfig", year: "2300"};
const config = new Config(storage, values);
const result = config.getValues();
assert.equal(result.name, "testConfig");
assert.equal(config.values.fromServer, undefined);
await config.pullFromServer();
assert.equal(config.values.fromServer, "yes");
mock.reset();
});
});

View File

@@ -58,6 +58,7 @@ func Import(router *gin.RouterGroup, conf *config.Config) {
event.Success(fmt.Sprintf("import completed in %d s", elapsed))
event.Publish("import.completed", event.Data{"path": path, "seconds": elapsed})
event.Publish("config.updated", event.Data(conf.ClientConfig()))
c.JSON(http.StatusOK, gin.H{"message": fmt.Sprintf("import completed in %d s", elapsed)})
})

View File

@@ -45,6 +45,7 @@ func Index(router *gin.RouterGroup, conf *config.Config) {
event.Success(fmt.Sprintf("indexing completed in %d s", elapsed))
event.Publish("index.completed", event.Data{"path": path, "seconds": elapsed})
event.Publish("config.updated", event.Data(conf.ClientConfig()))
c.JSON(http.StatusOK, gin.H{"message": fmt.Sprintf("indexing completed in %d s", elapsed)})
})

View File

@@ -30,7 +30,7 @@ func wsReader(ws *websocket.Conn) {
func wsWriter(ws *websocket.Conn, conf *config.Config) {
pingTicker := time.NewTicker(10 * time.Second)
s := event.Subscribe("index.*", "alert.*")
s := event.Subscribe("index.*", "upload.*", "import.*", "alert.*", "config.*")
defer func() {
pingTicker.Stop()