Skip to content

Commit

Permalink
Add Full Sync Button
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkLightTuna committed Dec 9, 2023
1 parent 171cdb7 commit 4a2323b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 49 deletions.
1 change: 1 addition & 0 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions src/settings-form-application.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

}
}

Expand Down Expand Up @@ -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
Expand Down
102 changes: 53 additions & 49 deletions templates/settings-form-application.hbs
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
<form autocomplete="off">
<div>
{{#unless valid_config}}
<h2>Installation Instructions</h2>
<ol>
<li>Invite the <a
href="https://discord.com/api/oauth2/authorize?client_id=1064553830810923048&permissions=18547851095248&scope=bot">
{{localize "oronder.Discord-Bot-Link-Title"}}</a> to your Discord.
</li>
<li>Subscribe to the <a href="https://discord.gg/27npDAXaCA\">
{{localize "oronder.Discord-Server-Link-Title"}}
</a> to gain access to advanced features.
</li>
<li>From your Discord, run "<code>/admin init</code>"</li>
<li>Copy your Discord server id, and the generated token into the fields below.</li>
<li>Clicking "<code>Fetch Discord User Ids</code>" 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.
</li>
</ol>
<hr>
{{/unless}}
<div>
{{#unless valid_config}}
<h2>Installation Instructions</h2>
<ol>
<li>Invite the <a
href="https://discord.com/api/oauth2/authorize?client_id=1064553830810923048&permissions=18547851095248&scope=bot">
{{localize "oronder.Discord-Bot-Link-Title"}}</a> to your Discord.
</li>
<li>Subscribe to the <a href="https://discord.gg/27npDAXaCA\">
{{localize "oronder.Discord-Server-Link-Title"}}
</a> to gain access to advanced features.
</li>
<li>From your Discord, run "<code>/admin init</code>"</li>
<li>Copy your Discord server id, and the generated token into the fields below.</li>
<li>Clicking "<code>Fetch Discord User Ids</code>" 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.
</li>
</ol>
<hr>
{{/unless}}

</div>
<div class="form-group">
<label for="guild_id">{{localize "oronder.Discord-Server-Id"}}</label>
<input type="text" name="guild_id" value="{{guild_id}}" required inputmode="numeric">
</div>

<div class="form-group">
<label for="auth">{{localize "oronder.Auth-Token"}}</label>
<input type="password" name="auth" value="{{auth}}" required>
</div>

<div class="form-group">
<button type="button" class='control' data-action='fetch' style="{{button_style}}">
<i class="{{fetch_button_icon}}"></i> {{fetch_button_msg}}
</button>
</div>
</div>
<div class="form-group">
<label for="guild_id">{{localize "oronder.Discord-Server-Id"}}</label>
<input type="text" name="guild_id" value="{{guild_id}}" required inputmode="numeric">
</div>

{{#if players}}
<hr>
<h3 class="border">{{localize "oronder.Discord-Ids"}}</h3>
{{/if}}
<div class="form-group">
<label for="auth">{{localize "oronder.Auth-Token"}}</label>
<input type="password" name="auth" value="{{auth}}" required>
</div>

{{#each players}}
<div class="form-group">
<label for="{{this.foundry_id}}">{{this.foundry_name}}</label>
<input type="text" name="{{this.foundry_id}}" inputmode="numeric" value="{{this.discord_id}}">
<button type="button" class='control' data-action='fetch' style="{{button_style}}">
<i class="{{fetch_button_icon}}"></i> {{fetch_button_msg}}
</button>
<button type="button" class='control' data-action='sync-all' style="{{button_style}}">
<i class="{{full_sync_button_icon}}"></i> {{full_sync_button_msg}}
</button>
</div>
{{/each}}

<hr>
<button type="submit">
<i class="far fa-save"></i> {{ localize "Save Changes" }}
</button>
{{#if players}}
<hr>
<h3 class="border">{{localize "oronder.Discord-Ids"}}</h3>
{{/if}}

{{#each players}}
<div class="form-group">
<label for="{{this.foundry_id}}">{{this.foundry_name}}</label>
<input type="text" name="{{this.foundry_id}}" inputmode="numeric" value="{{this.discord_id}}">
</div>
{{/each}}

<hr>
<button type="submit">
<i class="far fa-save"></i> {{ localize "Save Changes" }}
</button>

</form>

0 comments on commit 4a2323b

Please sign in to comment.