mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Update client config after upload, import or index
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import Api from "common/api";
|
import Event from "pubsub-js";
|
||||||
|
|
||||||
class Config {
|
class Config {
|
||||||
/**
|
/**
|
||||||
@@ -11,8 +11,7 @@ class Config {
|
|||||||
|
|
||||||
this.values = values;
|
this.values = values;
|
||||||
|
|
||||||
// this.setValues(JSON.parse(this.storage.getItem(this.storage_key)));
|
this.subscriptionId = Event.subscribe('config.updated', (ev, data) => this.setValues(data));
|
||||||
// this.setValues(values);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setValues(values) {
|
setValues(values) {
|
||||||
@@ -52,14 +51,6 @@ class Config {
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
pullFromServer() {
|
|
||||||
return Api.get("config").then(
|
|
||||||
(result) => {
|
|
||||||
this.setValues(result.data);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Config;
|
export default Config;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import Alert from "common/alert";
|
||||||
import Event from "pubsub-js";
|
import Event from "pubsub-js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -55,12 +56,12 @@
|
|||||||
this.$api.post('import').then(function () {
|
this.$api.post('import').then(function () {
|
||||||
ctx.busy = false;
|
ctx.busy = false;
|
||||||
ctx.completed = 100;
|
ctx.completed = 100;
|
||||||
this.fileName = '';
|
ctx.fileName = '';
|
||||||
}).catch(function () {
|
}).catch(function () {
|
||||||
this.$alert.error("Import failed");
|
Alert.error("Import failed");
|
||||||
ctx.busy = false;
|
ctx.busy = false;
|
||||||
ctx.completed = 0;
|
ctx.completed = 0;
|
||||||
this.fileName = '';
|
ctx.fileName = '';
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleEvent(ev, data) {
|
handleEvent(ev, data) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import Alert from "common/alert";
|
||||||
import Event from "pubsub-js";
|
import Event from "pubsub-js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -55,12 +56,12 @@
|
|||||||
this.$api.post('index').then(function () {
|
this.$api.post('index').then(function () {
|
||||||
ctx.busy = false;
|
ctx.busy = false;
|
||||||
ctx.completed = 100;
|
ctx.completed = 100;
|
||||||
this.fileName = '';
|
ctx.fileName = '';
|
||||||
}).catch(function () {
|
}).catch(function () {
|
||||||
this.$alert.error("Indexing failed");
|
Alert.error("Indexing failed");
|
||||||
ctx.busy = false;
|
ctx.busy = false;
|
||||||
ctx.completed = 0;
|
ctx.completed = 0;
|
||||||
this.fileName = '';
|
ctx.fileName = '';
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
handleEvent(ev, data) {
|
handleEvent(ev, data) {
|
||||||
|
|||||||
@@ -53,18 +53,4 @@ describe("common/config", () => {
|
|||||||
const result = config.getValue("city");
|
const result = config.getValue("city");
|
||||||
assert.equal(result, "Berlin");
|
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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
@@ -58,6 +58,7 @@ func Import(router *gin.RouterGroup, conf *config.Config) {
|
|||||||
|
|
||||||
event.Success(fmt.Sprintf("import completed in %d s", elapsed))
|
event.Success(fmt.Sprintf("import completed in %d s", elapsed))
|
||||||
event.Publish("import.completed", event.Data{"path": path, "seconds": 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)})
|
c.JSON(http.StatusOK, gin.H{"message": fmt.Sprintf("import completed in %d s", elapsed)})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ func Index(router *gin.RouterGroup, conf *config.Config) {
|
|||||||
|
|
||||||
event.Success(fmt.Sprintf("indexing completed in %d s", elapsed))
|
event.Success(fmt.Sprintf("indexing completed in %d s", elapsed))
|
||||||
event.Publish("index.completed", event.Data{"path": path, "seconds": 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)})
|
c.JSON(http.StatusOK, gin.H{"message": fmt.Sprintf("indexing completed in %d s", elapsed)})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func wsReader(ws *websocket.Conn) {
|
|||||||
|
|
||||||
func wsWriter(ws *websocket.Conn, conf *config.Config) {
|
func wsWriter(ws *websocket.Conn, conf *config.Config) {
|
||||||
pingTicker := time.NewTicker(10 * time.Second)
|
pingTicker := time.NewTicker(10 * time.Second)
|
||||||
s := event.Subscribe("index.*", "alert.*")
|
s := event.Subscribe("index.*", "upload.*", "import.*", "alert.*", "config.*")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
pingTicker.Stop()
|
pingTicker.Stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user