Skip to content

Commit

Permalink
Nov changes
Browse files Browse the repository at this point in the history
  • Loading branch information
datajohnson committed Nov 9, 2023
1 parent d12ab4c commit 5f38455
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 21 deletions.
10 changes: 3 additions & 7 deletions src/api/src/routes/answer-router.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import express, { Request, Response } from "express";
import { ReturnValidationErrors } from "../middleware";
import { param } from "express-validator";
import * as knex from "knex";
import { DB_CONFIG } from "../config";
import { AnswerService, EmailService, ParticipantService } from "../services";
import { AnswerService } from "../services";
import { checkJwt, loadUser } from "../middleware/authz.middleware";
import { Answer } from "src/data/models";

export const answerRouter = express.Router();

Expand All @@ -17,7 +12,7 @@ answerRouter.get("/", async (req: Request, res: Response) => {
res.json({ data: list });
});

answerRouter.put("/:id", async (req: Request, res: Response) => {
answerRouter.put("/:id", checkJwt, loadUser, async (req: Request, res: Response) => {
let { id } = req.params;
let { CATEGORY, DELETED_FLAG, DONE_MODERATING, MODERATED_HEADER, MODERATED_TEXT, MODERATOR_NOTES } = req.body;

Expand All @@ -28,6 +23,7 @@ answerRouter.put("/:id", async (req: Request, res: Response) => {
MODERATED_HEADER,
MODERATED_TEXT,
MODERATOR_NOTES,
MODERATED_BY: req.user.EMAIL,
});

res.json({ data: question });
Expand Down
2 changes: 1 addition & 1 deletion src/api/src/services/answer-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sample, sampleSize, shuffle } from "lodash";
import { sampleSize, shuffle } from "lodash";
import { DB_SCHEMA, DB_ANSWER_TABLE, DB_RATING_TABLE } from "../config";
import { db } from "../data";
import { Answer } from "../data/models";
Expand Down
1 change: 0 additions & 1 deletion src/api/src/services/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export class UserService implements GenericService<User> {
}

async getByEmail(EMAIL: string): Promise<User | undefined> {
console.log("LOOKING BY EMAIL", EMAIL);
if (EMAIL) {
let user = await db<User>(DB_USER_TABLE).withSchema(DB_SCHEMA).where({ EMAIL }).first();
return user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@
</v-row>
</v-card-text>
<v-card-actions class="mx-4 mb-2">
<v-btn color="primary" variant="flat" @click="saveClick">Moderation Complete</v-btn>
<v-btn color="primary" variant="flat" @click="saveClick" class="mr-4"
><v-icon class="mr-2">mdi-check</v-icon> Complete</v-btn
>
<v-btn color="primary" variant="flat" @click="saveNextClick" :disabled="!nextItem"
><v-icon class="mr-2">mdi-arrow-right</v-icon> Complete and Next</v-btn
>
<v-spacer></v-spacer>
<v-btn color="yg_sun" variant="outlined" @click="close">Close</v-btn>
</v-card-actions>
Expand All @@ -78,15 +83,23 @@ import { useResponseStore } from "../store";
export default {
name: "UserEditor",
props: ["items"],
data: () => ({}),
computed: {
...mapState(useResponseStore, ["response"]),
visible() {
return this.response ? true : false;
},
nextItem() {
if (this.items?.length < 1) return undefined;
let otherItems = this.items?.filter((i: any) => i.ID != this.response?.ID);
return otherItems ? otherItems[0] : undefined;
},
},
methods: {
...mapActions(useResponseStore, ["unselect", "update"]),
...mapActions(useResponseStore, ["select", "unselect", "update"]),
close() {
this.unselect();
},
Expand All @@ -99,6 +112,16 @@ export default {
});
}
},
saveNextClick() {
if (this.response) {
this.response.DONE_MODERATING = 1;
this.update().then(() => {
if (this.nextItem) this.select(this.nextItem);
else this.close();
});
}
},
},
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,22 @@
style="max-width: 300px"></v-select>
</template>

<v-data-table :search="search" :headers="headers" :items="filteredList" @click:row="rowClick"> </v-data-table>
<v-data-table :search="search" :headers="headers" :items="filteredList" @click:row="rowClick">
<template v-slot:item.DONE_MODERATING="{ item }">
{{ item.DONE_MODERATING == 1 ? "Yes" : "No" }}
</template>
<template v-slot:item.DELETED_FLAG="{ item }">
{{ item.DELETED_FLAG == 1 ? "Yes" : "No" }}
</template>
<template v-slot:item.MODERATED_TEXT="{ item }">
<span v-if="item.MODERATED_TEXT != item.ANSWER_TEXT" :class="`text-error`">{{ item.MODERATED_TEXT }}</span>
<span v-else>{{ item.MODERATED_TEXT }}</span>
</template>
</v-data-table>
</base-card>
</div>

<response-editor></response-editor>
<response-editor :items="filteredList"></response-editor>
</template>
<script lang="ts">
import { mapActions, mapState } from "pinia";
Expand All @@ -48,7 +59,7 @@ export default {
data: () => ({
headers: [
{ title: "Category", key: "CATEGORY" },
{ title: "Response", key: "ANSWER_TEXT" },
{ title: "Response", key: "MODERATED_TEXT" },
{ title: "Deleted", key: "DELETED_FLAG" },
{ title: "Complete", key: "DONE_MODERATING" },
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<h1>Responses</h1>

** maybe moderators only see unmoderated, admins see all
** maybe moderators only see unmoderated, admins see all
<base-card showHeader="t" heading="">
<template v-slot:left>
<v-select
Expand All @@ -31,7 +31,6 @@
style="width: 100px"></v-select>
</template>
<template v-slot:right>

<v-select
label="Status"
:items="['Unmoderated', 'Moderated']"
Expand All @@ -42,10 +41,21 @@
style="width: 100px"></v-select>
</template>

<v-data-table :search="search" :headers="headers" :items="filteredList" @click:row="rowClick"> </v-data-table>
<v-data-table :search="search" :headers="headers" :items="filteredList" @click:row="rowClick">
<template v-slot:item.DONE_MODERATING="{ item }">
{{ item.DONE_MODERATING == 1 ? "Yes" : "No" }}
</template>
<template v-slot:item.DELETED_FLAG="{ item }">
{{ item.DELETED_FLAG == 1 ? "Yes" : "No" }}
</template>
<template v-slot:item.MODERATED_TEXT="{ item }">
<span v-if="item.MODERATED_TEXT != item.ANSWER_TEXT" :class="`text-error`">{{ item.MODERATED_TEXT }}</span>
<span v-else>{{ item.MODERATED_TEXT }}</span>
</template>
</v-data-table>
</base-card>

<response-editor></response-editor>
<response-editor :items="filteredList"></response-editor>
</template>
<script lang="ts">
import { mapActions, mapState } from "pinia";
Expand All @@ -58,7 +68,7 @@ export default {
data: () => ({
headers: [
{ title: "Category", key: "CATEGORY" },
{ title: "Response", key: "ANSWER_TEXT" },
{ title: "Response", key: "MODERATED_TEXT" },
{ title: "Deleted", key: "DELETED_FLAG" },
{ title: "Complete", key: "DONE_MODERATING" },
],
Expand Down Expand Up @@ -87,9 +97,9 @@ export default {
}
if (this.status == "Moderated") {
items = items.filter((i) => (i.DONE_MODERATING == 1));
items = items.filter((i) => i.DONE_MODERATING == 1);
} else if (this.status == "Unmoderated") {
items = items.filter((i) => (i.DONE_MODERATING == 0));
items = items.filter((i) => i.DONE_MODERATING == 0);
}
return items;
Expand Down

0 comments on commit 5f38455

Please sign in to comment.