Skip to content

Commit 0848848

Browse files
From_timetable_to_rating_button (#339)
## Изменения Добавление функционала перехода со страницы преподавателя в расписании (например, [тут](https://app.profcomff.com/timetable/lecturer/666)) на его страницу в дубинушке ([сюда](https://rating.profcomff.com/lecturer?lecturer_id=1631), но в приложении). ## Детали реализации - Обновил библиотеку ApiUiLib (поддержка выкатки [ручки](https://api.test.profcomff.com/?urls.primaryName=rating#/Lecturer/get_lecturer_by_timetable_id_lecturer_timetable_id__timetable_id__get) ) - Добавил обвязку ручки. В api\controllers\TimetableApi.ts добавлены функция fetchLecturerByTimetableId и метод класса getLecturerByTimetableId - Добавил кнопку и функционал на ее нажатие в \views\timetable\lecturer\AsyncLecturerInfo.vue Co-authored-by: Илья Батуев <batuev.io18@physics.msu.ru>
1 parent e03723f commit 0848848

5 files changed

Lines changed: 68 additions & 16 deletions

File tree

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"check": "vue-tsc && pnpm run lint && pnpm run prettier && pnpm run stylelint"
2323
},
2424
"dependencies": {
25-
"@profcomff/api-uilib": "^2024.11.24",
2625
"markdown-it": "^14.1.0",
2726
"openapi-fetch": "^0.13.0",
2827
"pinia": "^2.2.6",
@@ -33,7 +32,7 @@
3332
},
3433
"devDependencies": {
3534
"@eslint/js": "^9.15.0",
36-
"@profcomff/api-uilib": "^2024.9.29",
35+
"@profcomff/api-uilib": "^2026.3.30",
3736
"@types/markdown-it": "^14.1.2",
3837
"@types/node": "^22.9.3",
3938
"@types/ua-parser-js": "^0.7.39",

pnpm-lock.yaml

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ function recordError(url: string, status: number, error: ApiError | undefined) {
2020

2121
const errorMiddleware: Middleware = {
2222
async onResponse({ response }) {
23-
const data = await response.clone();
23+
if (response.url.includes('marketing')) {
24+
return response;
25+
}
26+
27+
const data = response.clone();
28+
2429
if (!response.ok) {
2530
const error = await data.json();
2631
recordError(response.url, response.status, await error);

src/api/controllers/TimetableApi.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ function getLecturer(id: number) {
2626
});
2727
}
2828

29+
function fetchRatingLecturerByTimetableId(timetableId: number) {
30+
return apiClient.GET('/rating/lecturer/timetable-id/{timetable_id}', {
31+
params: { path: { timetable_id: timetableId } },
32+
});
33+
}
34+
2935
function getLecturers(params?: GetLecturersParams) {
3036
return apiClient.GET('/timetable/lecturer/', {
3137
params: { query: params },
@@ -49,6 +55,13 @@ export class TimetableApi {
4955
}
5056
}
5157

58+
public static async getRatingLecturerByTimetableId(
59+
timetableId: number
60+
): Promise<number | undefined> {
61+
const { data } = await fetchRatingLecturerByTimetableId(timetableId);
62+
return data?.id;
63+
}
64+
5265
public static async getRoom(id: number) {
5366
const { setRooms } = useTimetableStore();
5467
const { data } = await apiClient.GET('/timetable/room/{id}', {

src/views/timetable/lecturer/AsyncLecturerInfo.vue

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<script setup lang="ts">
22
import Placeholder from '@/assets/profile_image_placeholder.webp';
3-
import { computed } from 'vue';
3+
import Markdown from '@/components/MarkdownRenderer.vue';
44
import { TimetableApi } from '@/api';
55
import { useTimetableStore } from '@/store/timetable';
6-
import Markdown from '@/components/MarkdownRenderer.vue';
6+
import { computed, ref } from 'vue';
7+
import { useRouter } from 'vue-router';
78
89
const timetableStore = useTimetableStore();
10+
const router = useRouter();
911
1012
const props = defineProps<{ id: number }>();
1113
12-
const lecturerId = computed(() => props.id);
13-
14-
if (!timetableStore.lecturers.has(lecturerId.value)) {
14+
if (!timetableStore.lecturers.has(props.id)) {
1515
await TimetableApi.getLecturer(props.id);
1616
}
1717
@@ -27,14 +27,43 @@ const fullName = computed(() => {
2727
2828
const imgUrl = computed(() =>
2929
lecturer.value?.avatar_link
30-
? `${import.meta.env.VITE_API_URL}${lecturer.value?.avatar_link}`
30+
? `${import.meta.env.VITE_API_URL}${lecturer.value.avatar_link}`
3131
: Placeholder
3232
);
33+
34+
const isLoadingRating = ref(false);
35+
36+
async function goToRating() {
37+
isLoadingRating.value = true;
38+
try {
39+
const ratingId = await TimetableApi.getRatingLecturerByTimetableId(props.id);
40+
if (ratingId !== undefined) {
41+
await router.push(`/apps/44/lecturer?lecturer_id=${ratingId}`);
42+
}
43+
} finally {
44+
isLoadingRating.value = false;
45+
}
46+
}
3347
</script>
3448

3549
<template>
3650
<img :src="imgUrl" alt="Фотография преподавателя" class="avatar" width="256" height="256" />
3751
<h2 class="full-name">{{ fullName }}</h2>
52+
53+
<v-btn
54+
color="secondary"
55+
variant="flat"
56+
rounded="lg"
57+
class="rating-btn"
58+
:loading="isLoadingRating"
59+
@click="goToRating"
60+
>
61+
<template #prepend>
62+
<v-icon>nature</v-icon>
63+
</template>
64+
Рейтинг в «Дубинушке»
65+
</v-btn>
66+
3867
<Markdown class="description" :text="lecturer?.description ?? ''" />
3968
</template>
4069

@@ -56,6 +85,11 @@ const imgUrl = computed(() =>
5685
text-align: center;
5786
}
5887
88+
.rating-btn {
89+
align-self: center;
90+
margin-bottom: 16px;
91+
}
92+
5993
.description {
6094
margin-bottom: 64px;
6195
}

0 commit comments

Comments
 (0)