From 4a2323b6523408b2b1c1142c188d379271df8973 Mon Sep 17 00:00:00 2001 From: Christopher Renaud Oelerich Date: Sat, 9 Dec 2023 17:56:46 -0600 Subject: [PATCH] Add Full Sync Button --- languages/en.json | 1 + src/settings-form-application.mjs | 13 +++ templates/settings-form-application.hbs | 102 ++++++++++++------------ 3 files changed, 67 insertions(+), 49 deletions(-) diff --git a/languages/en.json b/languages/en.json index 08001c1..957b7ab 100644 --- a/languages/en.json +++ b/languages/en.json @@ -2,6 +2,7 @@ "oronder.Auth-Token": "Auth Token", "oronder.Discord-Server-Id": "Discord Server Id", "oronder.Fetch-Discord-User-Ids": "Fetch Discord User Ids", + "oronder.Full-Sync": "Full Sync", "oronder.Fetching-Discord-Ids": "Fetching Discord Ids", "oronder.Oronder-Configuration": "Oronder Configuration", "oronder.Configure-Oronder": "Configure Oronder", diff --git a/src/settings-form-application.mjs b/src/settings-form-application.mjs index f1ff861..4e42948 100644 --- a/src/settings-form-application.mjs +++ b/src/settings-form-application.mjs @@ -12,6 +12,8 @@ export class OronderSettingsFormApplication extends FormApplication { valid_config: game.settings.get(MODULE_ID, VALID_CONFIG), fetch_button_icon: "fa-solid fa-rotate", fetch_button_msg: game.i18n.localize("oronder.Fetch-Discord-User-Ids"), + full_sync_button_icon: "fa-solid fa-users", + full_sync_button_msg: game.i18n.localize("oronder.Full-Sync"), players: game.users.filter(user => user.role < 3).map(user => ({ foundry_name: user.name, foundry_id: user.id, @@ -51,6 +53,9 @@ export class OronderSettingsFormApplication extends FormApplication { switch (event.currentTarget.dataset.action) { case "fetch": return this._fetch_discord_ids(); + case "sync-all": + return this._full_sync() + } } @@ -119,6 +124,14 @@ export class OronderSettingsFormApplication extends FormApplication { this.render() } + async _full_sync() { + this.object.full_sync_button_icon = 'fa-solid fa-spinner fa-spin' + this.render() + await full_sync() + this.object.fetch_button_icon = "fa-solid fa-users" + this.render() + } + async _fetch_discord_ids() { this.object.guild_id = this.form.elements.guild_id.value this.object.auth = this.form.elements.auth.value diff --git a/templates/settings-form-application.hbs b/templates/settings-form-application.hbs index 9a3f37b..7f2fbed 100644 --- a/templates/settings-form-application.hbs +++ b/templates/settings-form-application.hbs @@ -1,58 +1,62 @@
-
- {{#unless valid_config}} -

Installation Instructions

-
    -
  1. Invite the - {{localize "oronder.Discord-Bot-Link-Title"}} to your Discord. -
  2. -
  3. Subscribe to the - {{localize "oronder.Discord-Server-Link-Title"}} - to gain access to advanced features. -
  4. -
  5. From your Discord, run "/admin init"
  6. -
  7. Copy your Discord server id, and the generated token into the fields below.
  8. -
  9. Clicking "Fetch Discord User Ids" will populate Discord user ids for players whose Discord name - matches their Foundry - name. For everyone else, you will need to manually add their user id. -
  10. -
-
- {{/unless}} +
+ {{#unless valid_config}} +

Installation Instructions

+
    +
  1. Invite the + {{localize "oronder.Discord-Bot-Link-Title"}} to your Discord. +
  2. +
  3. Subscribe to the + {{localize "oronder.Discord-Server-Link-Title"}} + to gain access to advanced features. +
  4. +
  5. From your Discord, run "/admin init"
  6. +
  7. Copy your Discord server id, and the generated token into the fields below.
  8. +
  9. Clicking "Fetch Discord User Ids" will populate Discord user ids for players whose + Discord name + matches their Foundry + name. For everyone else, you will need to manually add their user id. +
  10. +
+
+ {{/unless}} -
-
- - -
- -
- - -
- -
- -
+
+
+ + +
- {{#if players}} -
-

{{localize "oronder.Discord-Ids"}}

- {{/if}} +
+ + +
- {{#each players}}
- - + +
- {{/each}} -
- + {{#if players}} +
+

{{localize "oronder.Discord-Ids"}}

+ {{/if}} + + {{#each players}} +
+ + +
+ {{/each}} + +
+
\ No newline at end of file