diff --git a/.discourse-compatibility b/.discourse-compatibility index 5f0cd3e..2f02d14 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,3 +1,4 @@ +< 3.5.0.beta5-dev: be64a5ea30dcda658a74e22a9e7b5fd8cd7632c8 < 3.5.0.beta1-dev: b7181ad63238adf843d27b2d0db13cb6354df379 < 3.4.0.beta2-dev: ff810c65d88e3a208b1126e94ec9ba637d6e997e < 3.4.0.beta1-dev: 5a44de571484b2652d7ba57b16e3e1519e4d7317 diff --git a/Gemfile.lock b/Gemfile.lock index 6cc132b..c5be1a9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,30 +14,31 @@ GEM securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) uri (>= 0.13.1) - ast (2.4.2) - base64 (0.2.0) - benchmark (0.4.0) - bigdecimal (3.1.9) + ast (2.4.3) + base64 (0.3.0) + benchmark (0.4.1) + bigdecimal (3.2.0) concurrent-ruby (1.3.5) - connection_pool (2.5.0) - drb (2.2.1) + connection_pool (2.5.3) + drb (2.2.3) i18n (1.14.7) concurrent-ruby (~> 1.0) - json (2.10.2) - language_server-protocol (3.17.0.4) + json (2.12.2) + language_server-protocol (3.17.0.5) lint_roller (1.1.0) - logger (1.6.6) + logger (1.7.0) minitest (5.25.5) - parallel (1.26.3) - parser (3.3.7.1) + parallel (1.27.0) + parser (3.3.8.0) ast (~> 2.4.1) racc prettier_print (1.2.1) + prism (1.4.0) racc (1.8.1) - rack (3.1.12) + rack (3.1.15) rainbow (3.1.1) regexp_parser (2.10.0) - rubocop (1.74.0) + rubocop (1.75.8) json (~> 2.3) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.1.0) @@ -45,11 +46,12 @@ GEM parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 2.9.3, < 3.0) - rubocop-ast (>= 1.38.0, < 2.0) + rubocop-ast (>= 1.44.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 4.0) - rubocop-ast (1.38.1) - parser (>= 3.3.1.0) + rubocop-ast (1.44.1) + parser (>= 3.3.7.2) + prism (~> 1.4) rubocop-capybara (2.22.1) lint_roller (~> 1.1) rubocop (~> 1.72, >= 1.72.1) @@ -65,13 +67,13 @@ GEM rubocop-factory_bot (2.27.1) lint_roller (~> 1.1) rubocop (~> 1.72, >= 1.72.1) - rubocop-rails (2.30.3) + rubocop-rails (2.32.0) activesupport (>= 4.2.0) lint_roller (~> 1.1) rack (>= 1.1) - rubocop (>= 1.72.1, < 2.0) - rubocop-ast (>= 1.38.0, < 2.0) - rubocop-rspec (3.5.0) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.44.0, < 2.0) + rubocop-rspec (3.6.0) lint_roller (~> 1.1) rubocop (~> 1.72, >= 1.72.1) rubocop-rspec_rails (2.31.0) @@ -97,4 +99,4 @@ DEPENDENCIES syntax_tree BUNDLED WITH - 2.6.6 + 2.6.9 diff --git a/assets/javascripts/discourse-user-notes/connectors/admin-user-controls-after/add-user-notes-button.hbs b/assets/javascripts/discourse-user-notes/connectors/admin-user-controls-after/add-user-notes-button.hbs deleted file mode 100644 index d0137c3..0000000 --- a/assets/javascripts/discourse-user-notes/connectors/admin-user-controls-after/add-user-notes-button.hbs +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/assets/javascripts/discourse-user-notes/connectors/admin-user-controls-after/add-user-notes-button.js b/assets/javascripts/discourse-user-notes/connectors/admin-user-controls-after/add-user-notes-button.js deleted file mode 100644 index dd79869..0000000 --- a/assets/javascripts/discourse-user-notes/connectors/admin-user-controls-after/add-user-notes-button.js +++ /dev/null @@ -1,4 +0,0 @@ -import connector from "discourse/plugins/discourse-user-notes/discourse-user-notes/connectors/user-profile-controls/show-notes-on-profile"; - -// Same as other connector -export default connector; diff --git a/assets/javascripts/discourse-user-notes/connectors/after-reviewable-post-user/show-user-notes-on-flags.hbs b/assets/javascripts/discourse-user-notes/connectors/after-reviewable-post-user/show-user-notes-on-flags.hbs deleted file mode 100644 index 618d55a..0000000 --- a/assets/javascripts/discourse-user-notes/connectors/after-reviewable-post-user/show-user-notes-on-flags.hbs +++ /dev/null @@ -1,18 +0,0 @@ -{{#if this.userNotesCount}} - - {{#if this.emojiEnabled}} - - {{else}} - {{d-icon "pen-to-square"}} - {{/if}} - -{{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse-user-notes/connectors/after-reviewable-post-user/show-user-notes-on-flags.js b/assets/javascripts/discourse-user-notes/connectors/after-reviewable-post-user/show-user-notes-on-flags.js deleted file mode 100644 index ccc01db..0000000 --- a/assets/javascripts/discourse-user-notes/connectors/after-reviewable-post-user/show-user-notes-on-flags.js +++ /dev/null @@ -1,32 +0,0 @@ -import EmberObject from "@ember/object"; -import { getOwner } from "@ember/owner"; -import { emojiUrlFor } from "discourse/lib/text"; -import { i18n } from "discourse-i18n"; -import { showUserNotes } from "discourse/plugins/discourse-user-notes/discourse-user-notes/lib/user-notes"; - -export default { - shouldRender(args, component) { - return component.siteSettings.user_notes_enabled && args.user; - }, - - setupComponent(args, component) { - const model = EmberObject.create(args.user); - const userNotesCount = model.get("custom_fields.user_notes_count") || 0; - component.setProperties({ - userNotesCount, - emojiEnabled: component.siteSettings.enable_emoji, - emojiUrl: emojiUrlFor("memo"), - userNotesTitle: i18n("user_notes.show", { count: userNotesCount }), - }); - }, - - actions: { - showUserNotes() { - const store = getOwner(this).lookup("service:store"); - const user = this.get("args.user"); - showUserNotes(store, user.id, (count) => - this.set("userNotesCount", count) - ); - }, - }, -}; diff --git a/assets/javascripts/discourse-user-notes/connectors/user-profile-controls/show-notes-on-profile.hbs b/assets/javascripts/discourse-user-notes/connectors/user-profile-controls/show-notes-on-profile.hbs deleted file mode 100644 index d0137c3..0000000 --- a/assets/javascripts/discourse-user-notes/connectors/user-profile-controls/show-notes-on-profile.hbs +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/assets/javascripts/discourse-user-notes/connectors/user-profile-controls/show-notes-on-profile.js b/assets/javascripts/discourse-user-notes/connectors/user-profile-controls/show-notes-on-profile.js deleted file mode 100644 index b902e34..0000000 --- a/assets/javascripts/discourse-user-notes/connectors/user-profile-controls/show-notes-on-profile.js +++ /dev/null @@ -1,27 +0,0 @@ -import { getOwner } from "@ember/owner"; -import { showUserNotes } from "discourse/plugins/discourse-user-notes/discourse-user-notes/lib/user-notes"; - -export default { - shouldRender(args, component) { - const { siteSettings, currentUser } = component; - return siteSettings.user_notes_enabled && currentUser && currentUser.staff; - }, - - setupComponent(args, component) { - const { model } = args; - component.set( - "userNotesCount", - model.user_notes_count || model.get("custom_fields.user_notes_count") || 0 - ); - }, - - actions: { - showUserNotes() { - const store = getOwner(this).lookup("service:store"); - const user = this.get("args.model"); - showUserNotes(store, user.id, (count) => - this.set("userNotesCount", count) - ); - }, - }, -}; diff --git a/assets/javascripts/discourse/components/modal/user-notes.gjs b/assets/javascripts/discourse/components/modal/user-notes.gjs new file mode 100644 index 0000000..3f2d3bd --- /dev/null +++ b/assets/javascripts/discourse/components/modal/user-notes.gjs @@ -0,0 +1,134 @@ +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { Textarea } from "@ember/component"; +import { fn } from "@ember/helper"; +import { action } from "@ember/object"; +import { service } from "@ember/service"; +import CookText from "discourse/components/cook-text"; +import DButton from "discourse/components/d-button"; +import DModal from "discourse/components/d-modal"; +import UserLink from "discourse/components/user-link"; +import ageWithTooltip from "discourse/helpers/age-with-tooltip"; +import avatar from "discourse/helpers/avatar"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import { i18n } from "discourse-i18n"; + +export default class UserNotesModal extends Component { + @service dialog; + @service store; + + @tracked newNote; + @tracked userId = this.args.model.userId; + @tracked saving = false; + postId = this.args.model.postId; + callback = this.args.model.callback; + + #refreshCount() { + if (this.callback) { + this.callback(this.args.model.note.length); + } + } + + get attachDisabled() { + return this.saving || !this.newNote || this.newNote.length === 0; + } + + @action + async attachNote() { + const note = this.store.createRecord("user-note"); + const userId = parseInt(this.userId, 10); + + this.saving = true; + + const args = { + raw: this.newNote, + user_id: userId, + }; + + if (this.postId) { + args.post_id = parseInt(this.postId, 10); + } + + try { + await note.save(args); + this.newNote = ""; + this.args.model.note.insertAt(0, note); + this.#refreshCount(); + } catch (error) { + popupAjaxError(error); + } finally { + this.saving = false; + } + } + + @action + removeNote(note) { + this.dialog.deleteConfirm({ + message: i18n("user_notes.delete_confirm"), + didConfirm: () => { + note + .destroyRecord() + .then(() => { + this.args.model.note.removeObject(note); + this.#refreshCount(); + }) + .catch(popupAjaxError); + }, + }); + } + +