2024-04-09 10:03:07 -04:00
|
|
|
import Component from "@glimmer/component";
|
|
|
|
import { tracked } from "@glimmer/tracking";
|
|
|
|
import { action } from "@ember/object";
|
|
|
|
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
|
2024-11-19 05:57:40 -05:00
|
|
|
import { service } from "@ember/service";
|
2024-04-09 10:03:07 -04:00
|
|
|
import icon from "discourse-common/helpers/d-icon";
|
|
|
|
import { bind } from "discourse-common/utils/decorators";
|
|
|
|
import I18n from "discourse-i18n";
|
|
|
|
|
|
|
|
export default class RagUploadProgress extends Component {
|
|
|
|
@service messageBus;
|
|
|
|
@tracked updatedProgress = null;
|
|
|
|
|
|
|
|
willDestroy() {
|
|
|
|
super.willDestroy(...arguments);
|
2024-09-30 03:27:50 -04:00
|
|
|
this.messageBus.unsubscribe(`/discourse-ai/rag/${this.args.upload.id}`);
|
2024-04-09 10:03:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
trackProgress() {
|
|
|
|
this.messageBus.subscribe(
|
2024-09-30 03:27:50 -04:00
|
|
|
`/discourse-ai/rag/${this.args.upload.id}`,
|
2024-04-09 10:03:07 -04:00
|
|
|
this.onIndexingUpdate
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@bind
|
|
|
|
onIndexingUpdate(data) {
|
|
|
|
// Order not guaranteed. Discard old updates.
|
2024-04-25 09:48:55 -04:00
|
|
|
if (
|
|
|
|
!this.updatedProgress ||
|
2024-09-30 03:27:50 -04:00
|
|
|
this.updatedProgress.left === 0 ||
|
|
|
|
this.updatedProgress.left > data.left ||
|
|
|
|
data.total === data.indexed
|
2024-04-25 09:48:55 -04:00
|
|
|
) {
|
2024-04-09 10:03:07 -04:00
|
|
|
this.updatedProgress = data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get calculateProgress() {
|
2024-04-25 09:48:55 -04:00
|
|
|
if (this.progress.total === 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-04-09 10:03:07 -04:00
|
|
|
return Math.ceil((this.progress.indexed * 100) / this.progress.total);
|
|
|
|
}
|
|
|
|
|
|
|
|
get fullyIndexed() {
|
2024-04-25 09:48:55 -04:00
|
|
|
return (
|
|
|
|
this.progress && this.progress.total !== 0 && this.progress.left === 0
|
|
|
|
);
|
2024-04-09 10:03:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
get progress() {
|
|
|
|
if (this.updatedProgress) {
|
|
|
|
return this.updatedProgress;
|
|
|
|
} else if (this.args.ragIndexingStatuses) {
|
|
|
|
return this.args.ragIndexingStatuses[this.args.upload.id];
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
<template>
|
2024-09-30 03:27:50 -04:00
|
|
|
<td class="rag-uploader__upload-status" {{didInsert this.trackProgress}}>
|
2024-04-09 10:03:07 -04:00
|
|
|
{{#if this.progress}}
|
|
|
|
{{#if this.fullyIndexed}}
|
|
|
|
<span class="indexed">
|
|
|
|
{{icon "check"}}
|
2024-09-30 03:27:50 -04:00
|
|
|
{{I18n.t "discourse_ai.rag.uploads.indexed"}}
|
2024-04-09 10:03:07 -04:00
|
|
|
</span>
|
|
|
|
{{else}}
|
|
|
|
<span class="indexing">
|
|
|
|
{{icon "robot"}}
|
2024-09-30 03:27:50 -04:00
|
|
|
{{I18n.t "discourse_ai.rag.uploads.indexing"}}
|
2024-04-09 10:03:07 -04:00
|
|
|
{{this.calculateProgress}}%
|
|
|
|
</span>
|
|
|
|
{{/if}}
|
|
|
|
{{else}}
|
|
|
|
<span class="uploaded">{{I18n.t
|
2024-09-30 03:27:50 -04:00
|
|
|
"discourse_ai.rag.uploads.uploaded"
|
2024-04-09 10:03:07 -04:00
|
|
|
}}</span>
|
|
|
|
{{/if}}
|
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
}
|