-
Notifications
You must be signed in to change notification settings - Fork 0
Admin page #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Admin page #57
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f6fe29e
Merge pull request #50 from Keukeiland/fizitzfux
fizitzfux 70af9ee
Fixed registration_date mismatch
RemainingDev cc2ba07
Merge pull request #56 from Keukeiland/main
RemainingDev 7c2bd59
Update package.json
RemainingDev 065bf80
Added admin page
RemainingDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,36 @@ | ||
| {% extends "extension.html" %} | ||
|
|
||
| {% block head %} | ||
| <link href="/admin/index.css" rel="stylesheet"> | ||
| {% endblock %} | ||
|
|
||
|
|
||
| {% block body %} | ||
| <h3>This page is currently under development and will be available soon!</h3> | ||
| <table id="user_table"> | ||
| <thead> | ||
| <tr> | ||
| <th>ID</th> | ||
| <th>Name</th> | ||
| <th>Registration Date</th> | ||
| <th>Is Admin</th> | ||
| <th>Actions</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for info in user_info %} | ||
| <tr> | ||
| <td>{{info.id}}</td> | ||
| <td>{{info.name}}</td> | ||
| <td>{{info.registration_date}}</td> | ||
| <td>{{"Yes" if info.is_admin else "No"}}</td> | ||
| <td class="actionCells"> | ||
| <a href="/admin/toggle_admin?id={{info.id}}" class="button">{{"Remove Admin" if info.is_admin else "Make Admin"}}</a> | ||
| <a href="/admin/remove_account?id={{info.id}}" class="button">Remove Account</a> | ||
| </td> | ||
| </tr> | ||
| {% else %} | ||
| <p>No users</p> | ||
| {% endfor %} | ||
| </tbody> | ||
| </table> | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,60 @@ | ||
| import { ExtensionBase } from "../../modules.ts" | ||
| import { ExtensionBase, Knex } from '../../modules.ts' | ||
| import { unpack } from '../../util.ts' | ||
|
|
||
| export default class extends ExtensionBase { | ||
| override name = 'admin' | ||
| override title = 'Admin' | ||
| override admin_only = true | ||
|
|
||
| override handle: Extension['handle'] = (ctx) => { | ||
| this.return_html(ctx, 'index') | ||
| user_info: {id: any, username: any, reg_date: any, admin: any}[] = [] | ||
| sortingType = "id" | ||
|
|
||
| override handle: Extension['handle'] = async (ctx) => { | ||
| let [knex]: [Knex] = this.get_dependencies('Knex') | ||
| var location = ctx.path.shift() | ||
|
|
||
| switch (location) { | ||
| case '': | ||
| case undefined:{ | ||
| var [user_list, err] = await knex | ||
| .query('user') | ||
| .select<User[]>('*') | ||
| .then(unpack<User[]>) | ||
|
|
||
| ctx.context.user_info = user_list | ||
| return this.return_html(ctx, 'index', err) | ||
| } | ||
| case 'toggle_admin':{ | ||
| var id = ctx.args.get("id") | ||
|
|
||
| var [user, err] = await knex | ||
| .query('user') | ||
| .select<User>('*') | ||
| .where('id', id) | ||
| .first() | ||
| .then(unpack<User>) | ||
|
|
||
| await knex | ||
| .query('user') | ||
| .update('is_admin', !user?.is_admin) | ||
| .where('id', id) | ||
|
|
||
| return this.return(ctx, undefined, location='/admin') | ||
| } | ||
| case 'remove_account':{ | ||
| var id = ctx.args.get("id") | ||
|
|
||
| await knex | ||
| .query('user') | ||
| .where('id', id) | ||
| .delete('*') | ||
|
|
||
| return this.return(ctx, undefined, location='/admin') | ||
| } | ||
| default: { | ||
| return this.return_file(ctx, location) | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #user_table{ | ||
| border-collapse: collapse; | ||
| margin: 10px, 0; | ||
| } | ||
|
|
||
| #user_table thead tr{ | ||
| text-align: center; | ||
| font-weight: bold; | ||
| } | ||
|
|
||
| #user_table tbody tr{ | ||
| text-align: center; | ||
| border-bottom: 1px black; | ||
| } | ||
|
|
||
| #user_table tbody tr:nth-of-type(even){ | ||
| background-color: rgb(192, 192, 192); | ||
| } | ||
|
|
||
| #user_table th, | ||
| #user_table td{ | ||
| padding: 6px 8px; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please end all files with a newline.
Won't block merging on this though.