Skip to content

Commit

Permalink
wip link minecraft
Browse files Browse the repository at this point in the history
  • Loading branch information
FunixG committed May 18, 2024
1 parent dc03f9e commit 9c7efd1
Show file tree
Hide file tree
Showing 16 changed files with 306 additions and 14 deletions.
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@angular/platform-server": "^17.3.7",
"@angular/router": "^17.3.7",
"@angular/ssr": "^17.3.6",
"@funixproductions/funixproductions-requests": "^0.1.15",
"@funixproductions/funixproductions-requests": "^0.1.17",
"@ng-bootstrap/ng-bootstrap": "^16.0.0",
"@popperjs/core": "^2.11.8",
"bootstrap": "^5.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<img
ngSrc="https://minotar.net/avatar/{{ username }}/{{ size }}.png"
[width]="size"
[height]="size"
alt="Slin Minecraft de {{ username}}"

This comment has been minimized.

Copy link
@iGameCreep

iGameCreep May 18, 2024

Member

"Slin" au lieu de "skin" (alt de l'image)

>
Empty file.
23 changes: 23 additions & 0 deletions src/app/components/minecraft-head/minecraft-head.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {ComponentFixture, TestBed} from '@angular/core/testing';

import {MinecraftHeadComponent} from './minecraft-head.component';

describe('MinecraftHeadComponent', () => {
let component: MinecraftHeadComponent;
let fixture: ComponentFixture<MinecraftHeadComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MinecraftHeadComponent]
})
.compileComponents();

fixture = TestBed.createComponent(MinecraftHeadComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
18 changes: 18 additions & 0 deletions src/app/components/minecraft-head/minecraft-head.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {Component, Input} from '@angular/core';
import {NgOptimizedImage} from "@angular/common";

@Component({
selector: 'minecraft-head',
standalone: true,
imports: [
NgOptimizedImage
],
templateUrl: './minecraft-head.component.html',
styleUrl: './minecraft-head.component.scss'
})
export class MinecraftHeadComponent {

@Input() username: string = '';
@Input() size: number = 100;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>user-account-integrations-minecraft-account-create-new works!</p>
<button class="btn btn-danger" (click)="close()">
test
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {ComponentFixture, TestBed} from '@angular/core/testing';

import {
UserAccountIntegrationsMinecraftAccountCreateNewComponent
} from './user-account-integrations-minecraft-account-create-new.component';

describe('UserAccountIntegrationsMinecraftAccountCreateNewComponent', () => {
let component: UserAccountIntegrationsMinecraftAccountCreateNewComponent;
let fixture: ComponentFixture<UserAccountIntegrationsMinecraftAccountCreateNewComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [UserAccountIntegrationsMinecraftAccountCreateNewComponent]
})
.compileComponents();

fixture = TestBed.createComponent(UserAccountIntegrationsMinecraftAccountCreateNewComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {Component, Input} from '@angular/core';
import {ErrorDto, PacifistaWebUserLinkService, UserDTO} from "@funixproductions/funixproductions-requests";
import {NgbActiveModal} from "@ng-bootstrap/ng-bootstrap";
import {HttpClient} from "@angular/common/http";
import NotificationService from "../../../../../../../../services/notifications/services/NotificationService";
import {environment} from "../../../../../../../../../environments/environment";

@Component({
selector: 'app-user-account-integrations-minecraft-account-create-new',
standalone: true,
imports: [],
templateUrl: './user-account-integrations-minecraft-account-create-new.component.html',
styleUrl: './user-account-integrations-minecraft-account-create-new.component.scss'
})
export class UserAccountIntegrationsMinecraftAccountCreateNewComponent {

private readonly linkService: PacifistaWebUserLinkService

@Input() user?: UserDTO
minecraftUsername: string = ''
errorStr?: string

constructor(public activeModal: NgbActiveModal,
private notificationService: NotificationService,
http: HttpClient) {
this.linkService = new PacifistaWebUserLinkService(http, environment.production)
}

createLink(): void {
this.errorStr = undefined

if (this.minecraftUsername.length === 0) {
this.errorStr = 'Le nom d\'utilisateur Minecraft ne peut pas être vide.';
return
}

this.linkService.linkUser(this.minecraftUsername).subscribe({
next: (link) => {
this.activeModal.close()
this.notificationService.info('Le compte Minecraft a été lié avec succès.')
},
error: (error: ErrorDto) => {
this.errorStr = error.error
}
})
}

close() {
this.activeModal.close()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div class="row justify-content-between">
<div class="col-10">
<h2>Compte Minecraft</h2>
</div>
<div class="col-2">
<button class="btn btn-outline-success" (click)="refresh()">
<i class="bi bi-arrow-clockwise"></i>
</button>
</div>
</div>

<div *ngIf="loading; else doneLoading">
<div class="spinner-border text-light" role="status">
<span class="visually-hidden">Chargement...</span>
</div>
</div>
<ng-template #doneLoading>
<div *ngIf="link; else notLinked">
<div class="row">
<div class="col-2 align-content-center">
<minecraft-head
[username]="link.minecraftUsername ?? ''"
[size]="64">
</minecraft-head>
</div>
<div class="col align-content-center">
<h3>{{ link.minecraftUsername }}</h3>
<button class="btn btn-danger" (click)="unlink()">
Délier le compte
</button>
</div>
</div>
</div>
<ng-template #notLinked>
<div *ngIf="error; else noErrorOnLink">
<p style="color: red">Une erreur est survenue veuillez réessayer ou contacter un admin.</p>
</div>
<ng-template #noErrorOnLink>
<p>Vous n'avez pas encore lié votre compte Minecraft.</p>
<button class="btn btn-success" (click)="openCreationModal()">
<i class="bi bi-link"></i>
Lier le compte Minecraft
</button>
</ng-template>
</ng-template>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h2 {
font-size: 1.5rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {ComponentFixture, TestBed} from '@angular/core/testing';

import {
UserAccountIntegrationsMinecraftAccountComponent
} from './user-account-integrations-minecraft-account.component';

describe('UserAccountIntegrationsMinecraftAcccountComponent', () => {
let component: UserAccountIntegrationsMinecraftAccountComponent;
let fixture: ComponentFixture<UserAccountIntegrationsMinecraftAccountComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [UserAccountIntegrationsMinecraftAccountComponent]
})
.compileComponents();

fixture = TestBed.createComponent(UserAccountIntegrationsMinecraftAccountComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {AfterViewInit, Component, Input} from '@angular/core';
import {
ErrorDto,
PacifistaWebUserLinkDTO,
PacifistaWebUserLinkService,
UserDTO
} from "@funixproductions/funixproductions-requests";
import {HttpClient} from "@angular/common/http";
import {environment} from "../../../../../../../../environments/environment";
import NotificationService from "../../../../../../../services/notifications/services/NotificationService";
import {NgbModal} from "@ng-bootstrap/ng-bootstrap";
import {
UserAccountIntegrationsMinecraftAccountCreateNewComponent
} from "./user-account-integrations-minecraft-account-create-new/user-account-integrations-minecraft-account-create-new.component";

@Component({
selector: 'app-user-account-integrations-minecraft-acccount',
templateUrl: './user-account-integrations-minecraft-account.component.html',
styleUrl: './user-account-integrations-minecraft-account.component.scss'
})
export class UserAccountIntegrationsMinecraftAccountComponent implements AfterViewInit {

private readonly linkService: PacifistaWebUserLinkService

@Input() user: UserDTO = new UserDTO()
link?: PacifistaWebUserLinkDTO

error: boolean = false
loading: boolean = true

constructor(httpClient: HttpClient,
private notificationService: NotificationService,
private modalService: NgbModal) {
this.linkService = new PacifistaWebUserLinkService(httpClient, environment.production)
}

ngAfterViewInit(): void {
this.refresh()
}

refresh() {
this.error = false
this.loading = true

this.linkService.getCurrentUserLink().subscribe({
next: (link) => {
this.link = link
this.loading = false
},
error: (error: ErrorDto) => {
this.link = undefined

if (error.status !== 404) {
this.error = true
this.notificationService.onErrorRequest(error)
}
this.loading = false
}
})
}

unlink(): void {
this.linkService.unlinkUser().subscribe({
next: () => {
this.link = undefined
this.notificationService.info('Le compte Minecraft a été délié avec succès.')
},
error: (error: ErrorDto) => {
this.notificationService.onErrorRequest(error)
}
})
}

openCreationModal() {
const modalRef = this.modalService.open(UserAccountIntegrationsMinecraftAccountCreateNewComponent, { centered: true});
modalRef.componentInstance.user = this.user;
modalRef.closed.subscribe({
next: () => {
this.refresh()
}
})
}

}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>user-account-integrations works!</p>
<app-user-account-integrations-minecraft-acccount [user]="user"></app-user-account-integrations-minecraft-acccount>
10 changes: 8 additions & 2 deletions src/app/pages/user/user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import {
import {
UserAccountInfosPasswordChangeComponent
} from "./user-page/components/user-account-infos/components/user-account-infos-password-change/user-account-infos-password-change.component";
import {
UserAccountIntegrationsMinecraftAccountComponent
} from "./user-page/components/user-account-integrations/components/user-account-integrations-minecraft-acccount/user-account-integrations-minecraft-account.component";
import {MinecraftHeadComponent} from "../../components/minecraft-head/minecraft-head.component";

@NgModule({
declarations: [
Expand All @@ -44,7 +48,8 @@ import {
UserAccountIntegrationsComponent,
UserAccountInvoicesComponent,
UserAccountInfosPersonalDataComponent,
UserAccountInfosPasswordChangeComponent
UserAccountInfosPasswordChangeComponent,
UserAccountIntegrationsMinecraftAccountComponent
],
imports: [
CommonModule,
Expand All @@ -57,7 +62,8 @@ import {
SendButtonComponent,
InputTextComponent,
InputSecretComponent,
InputCheckboxComponent
InputCheckboxComponent,
MinecraftHeadComponent
],
providers: [
{
Expand Down

0 comments on commit 9c7efd1

Please sign in to comment.