Skip to content
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

Отметка тех, кому было отправлен "Вызов" #61

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/migrations/2024-10-10-091714_call/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE participants
DROP COLUMN has_call;
2 changes: 2 additions & 0 deletions backend/migrations/2024-10-10-091714_call/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE participants
ADD has_call BOOLEAN DEFAULT FALSE NOT NULL;
5 changes: 5 additions & 0 deletions backend/src/api/payloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub struct UpdateParticipantPayload {
pub answers: HashMap<String, String>,
}

#[derive(Deserialize)]
pub struct ParticipantCallPayload {
pub has_call: bool,
}

#[derive(Deserialize)]
pub struct SetParticipantCommandPayload {
pub jury_id: Option<AdultId>,
Expand Down
1 change: 1 addition & 0 deletions backend/src/api/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn orgs_methods() -> Router<Arc<BackendState>> {
.delete(org::delete_participant)
.patch(org::patch_participant),
)
.route("/participant/:id/call", post(org::call_participant))
.route("/participant/:id/command", post(org::set_command))
.route("/adults", get(org::all_adults))
.route("/adult", post(org::create_adult))
Expand Down
13 changes: 13 additions & 0 deletions backend/src/api/v1/org.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ pub async fn patch_participant(
.map_err(Into::into)
}

pub async fn call_participant(
State(state): State<Arc<BackendState>>,
Path(id): Path<ParticipantId>,
Json(ParticipantCallPayload { has_call }): Json<ParticipantCallPayload>,
) -> Result<()> {
state
.datasource
.participants
.set_has_call(id, has_call)
.await
.map_err(Into::into)
}

pub async fn set_command(
State(state): State<Arc<BackendState>>,
Path(id): Path<ParticipantId>,
Expand Down
1 change: 1 addition & 0 deletions backend/src/datasource/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub struct Participant {
pub responsible_adult_phone_number: String,
pub jury_id: Option<i32>,
pub deleted_by: Option<i32>,
pub has_call: bool,
pub answers: serde_json::Value,
}

Expand Down
23 changes: 23 additions & 0 deletions backend/src/datasource/participants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl Participants {
code: participant.code,
jury,
deleted_by,
has_call: participant.has_call,
info: ParticipantInfo {
name: participant.name,
photo_url: participant.photo_url,
Expand Down Expand Up @@ -221,6 +222,10 @@ impl Participants {
Order::Asc => query.order_by(participants::city.asc()).load(conn)?,
Order::Desc => query.order_by(participants::city.desc()).load(conn)?,
},
Sort::HasCall => match order {
Order::Asc => query.order_by(participants::has_call.asc()).load(conn)?,
Order::Desc => query.order_by(participants::has_call.desc()).load(conn)?,
},
};

participants
Expand All @@ -235,6 +240,7 @@ impl Participants {
deleted_by: participant
.deleted_by
.map(|jury_id| adults.get(&AdultId(jury_id)).cloned().unwrap()),
has_call: participant.has_call,
info: ParticipantInfo {
name: participant.name,
photo_url: participant.photo_url,
Expand Down Expand Up @@ -321,6 +327,23 @@ impl Participants {
.await
}

pub async fn set_has_call(&self, id: ParticipantId, has_call: bool) -> Result<()> {
transact(self.conn.clone(), move |conn| {
let participant_exists = Self::participant_exists(conn, id)?;
if !participant_exists {
return Err(DataSourceError::UnknownParticipant(id));
}

diesel::update(participants::table)
.filter(participants::id.eq(id.0))
.set(participants::has_call.eq(has_call))
.execute(conn)?;

Ok(())
})
.await
}

pub async fn set_jury(&self, id: ParticipantId, jury_id: Option<AdultId>) -> Result<()> {
transact(self.conn.clone(), move |conn| {
let participant_exists = Self::participant_exists(conn, id)?;
Expand Down
7 changes: 2 additions & 5 deletions backend/src/datasource/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@ diesel::table! {
answers -> Jsonb,
jury_id -> Nullable<Int4>,
deleted_by -> Nullable<Int4>,
has_call -> Bool,
}
}

diesel::joinable!(participant_rates -> adults (jury_id));
diesel::joinable!(participant_rates -> participants (participant_id));

diesel::allow_tables_to_appear_in_same_query!(
adults,
participant_rates,
participants,
);
diesel::allow_tables_to_appear_in_same_query!(adults, participant_rates, participants,);
1 change: 1 addition & 0 deletions backend/src/domain/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ pub enum Sort {
Name,
District,
City,
HasCall,
}
1 change: 1 addition & 0 deletions backend/src/domain/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Participant {
pub code: ParticipantCode,
pub jury: Option<Adult>,
pub deleted_by: Option<Adult>,
pub has_call: bool,
pub info: ParticipantInfo,
pub answers: ParticipantAnswers,
pub rates: HashMap<AdultId, Option<ParticipantRate>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ <h3 class="participant__title">
@switch (status) {
@case (ParticipantStatus.InTeam) {
<p class="participant__status in-team">
Находится в команде "{{ participant.jury?.name ?? '' }}"
@if (participant.has_call) {
Находится в команде "{{ participant.jury!.name }}". Вызов сделан
} @else {
Находится в команде "{{ participant.jury!.name }}"
}
</p>
}
@case (ParticipantStatus.NotRated) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<span nz-icon nzType="edit" nzTheme="outline"></span>
Редактировать
</button>

<nz-spin [nzSpinning]="isDeleting">
<button
nz-button
Expand Down Expand Up @@ -48,14 +48,25 @@
(nzOnConfirm)="cancelEdit()"
>
<span nz-icon nzType="rollback" nzTheme="outline"></span>
Отменить
</button>
</nz-spin>
}
}
</div>

@if (participant.jury) {
<nz-card class="participant-call" [nzBodyStyle]="{'padding': '1em'}">
<nz-spin [nzSpinning]="isCalling">
<label nz-checkbox [(ngModel)]="participant.has_call" (ngModelChange)="callParticipant()">
Вызов сделан
</label>
</nz-spin>
</nz-card>
}

<nz-card class="participant-card" [nzBodyStyle]="{'padding': '0'}">
<div class="participant-card__content">
<div class="participant-card__content">
@if (mode === Mode.View) {
<!-- TODO(vklachkov): Вынести в компонент -->
<div class="info">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
}
}

.participant-call {
margin-bottom: 0.5em;
}

.participant-card {
margin-bottom: 0.5em;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { OrganizerService } from '@services/organizer.service';
import { DownloadService } from '@services/download.service';
import { Answers, Participant, ParticipantInfo } from '@models/api/participant.interface';
import { ParticipantUpdateInfo } from '@models/api/participant-update-info.interface';
import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';

export enum Mode {
View,
Expand Down Expand Up @@ -64,14 +65,16 @@ type FormValue = Omit<ParticipantInfo, 'photo_url'> & { answers: Answers };
FormsModule,
ReactiveFormsModule,
AnswersComponent,
AnswersEditableComponent
AnswersEditableComponent,
NzCheckboxModule,
],
templateUrl: './participant-questionnarie-tab.component.html',
styleUrl: './participant-questionnarie-tab.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ParticipantQuestionnarieTabComponent extends BaseComponent implements OnDestroy {
protected isDeleting: boolean = false;
protected isCalling: boolean = false;
protected isParticipantInfoUpdating: boolean = false;

protected readonly Mode = Mode;
Expand Down Expand Up @@ -154,9 +157,32 @@ export class ParticipantQuestionnarieTabComponent extends BaseComponent implemen
this.cdr.markForCheck();
}

callParticipant(): void {
this.isCalling = true;
this.cdr.markForCheck();

this.organizerService.setParticipantHasCall(this.participant.id, this.participant.has_call)
.pipe(takeUntil(this.destroy$))
.subscribe({
next: () => {
this.isCalling = false;
this.cdr.markForCheck();
},
error: (err: HttpErrorResponse) => {
this.isCalling = false;
this.participant.has_call = !this.participant.has_call;
this.cdr.markForCheck();

this.showErrorNotification('Ошибка при вызове участника', err);
}
});
}

remove(): void {
this.isDeleting = true;
this.organizerService.removeParticipant((<Participant>this.participant).id)
this.cdr.markForCheck();

this.organizerService.removeParticipant(this.participant.id)
.pipe(takeUntil(this.destroy$))
.subscribe({
next: () => {
Expand All @@ -165,6 +191,7 @@ export class ParticipantQuestionnarieTabComponent extends BaseComponent implemen
error: (err: HttpErrorResponse) => {
this.isDeleting = false;
this.cdr.markForCheck();

this.showErrorNotification('Ошибка при удалении участника', err);
}
});
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/models/api/participant.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface Participant {
code: string,
// Жюри (если есть, значит он в команде)
jury: Adult | null,
// Вызов сделан?
has_call: boolean,
// Жюри, который удалил участника
deleted_by: Adult | null,
// Базовая информация
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/models/api/sort.enum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum Sort {
Id = 'id',
Name = 'name',
City = 'city',
District = 'district',
City = 'city'
HasCall = 'has_call',
}
1 change: 1 addition & 0 deletions frontend/src/app/pages/organizer/organizer.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<label nz-radio [nzValue]="Sort.Name">Имя</label>
<label nz-radio [nzValue]="Sort.City">Город</label>
<label nz-radio [nzValue]="Sort.District">Район</label>
<label nz-radio [nzValue]="Sort.HasCall">По вызову</label>
</nz-radio-group>
</div>

Expand Down
7 changes: 7 additions & 0 deletions frontend/src/app/pages/organizer/organizer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const ASC_SORT_NUMERIC_LABEL: string = 'От старых к новым';
const DESC_SORT_NUMBERIC_LABEL: string = 'От новых к старым';
const ASC_SORT_LETTER_LABEL: string = 'От А до Я';
const DESC_SORT_LETTER_LABEL: string = 'От Я до А';
const ASC_SORT_CALL_LABEL: string = 'Сначала без вызова';
const DESC_SORT_CALL_LABEL: string = 'Сначала с вызовом';

@Component({
selector: 'app-organizer-page',
Expand Down Expand Up @@ -239,6 +241,11 @@ export class OrganizerPage extends BaseComponent implements OnInit, OnDestroy {
this.descSortLabel = DESC_SORT_LETTER_LABEL;
break;
}
case Sort.HasCall: {
this.ascSortLabel = ASC_SORT_CALL_LABEL;
this.descSortLabel = DESC_SORT_CALL_LABEL;
break;
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions frontend/src/app/services/organizer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export class OrganizerService {
return this.http.get<Participant | null>(`${environment.API_URL}/org/participant/${id}`);
}

setParticipantHasCall(participantId: number, hasCall: boolean): Observable<void> {
return this.http.post<void>(`${environment.API_URL}/org/participant/${participantId}/call`, {
has_call: hasCall
});
}

setParticipantCommand(participantId: number, juryId: number | null): Observable<void> {
return this.http.post<void>(`${environment.API_URL}/org/participant/${participantId}/command`, {
jury_id: juryId
Expand Down
Loading