School Commit Init
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<div class="container text-center">
|
||||
<h3>Welcome</h3>
|
||||
<table
|
||||
class="container"
|
||||
id="newsTable"
|
||||
style="
|
||||
margin: 30px;
|
||||
border: 1px solid;
|
||||
border-color: black;
|
||||
border-collapse: collapse;
|
||||
"
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Content</th>
|
||||
<th>Category</th>
|
||||
<th>Date</th>
|
||||
<th>Producer</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (item of news; track $index) {
|
||||
<tr>
|
||||
<td>{{ item.title }}</td>
|
||||
<td>{{ item.news_text }}</td>
|
||||
<td>{{ item.category }}</td>
|
||||
<td>{{ item.date }}</td>
|
||||
<td>{{ item.producer }}</td>
|
||||
<td>
|
||||
<button
|
||||
class="btn btn-danger"
|
||||
name="deleteButton"
|
||||
(click)="editNews(item.id)"
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
<button
|
||||
type="submit"
|
||||
class="btn btn-primary"
|
||||
name="addNewsButton"
|
||||
(click)="addNews()"
|
||||
style="margin: 30px"
|
||||
>
|
||||
Add news
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
class="btn btn-dark"
|
||||
name="logoutButton"
|
||||
(click)="logout()"
|
||||
style="margin: 30px"
|
||||
>
|
||||
Log out
|
||||
</button>
|
||||
</table>
|
||||
</div>
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AdminPageComponent } from './admin-page.component';
|
||||
|
||||
describe('AdminPageComponent', () => {
|
||||
let component: AdminPageComponent;
|
||||
let fixture: ComponentFixture<AdminPageComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [AdminPageComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(AdminPageComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import News from '../../types/news';
|
||||
|
||||
@Component({
|
||||
selector: 'app-admin-page',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './admin-page.component.html',
|
||||
styleUrl: './admin-page.component.less'
|
||||
})
|
||||
export class AdminPageComponent {
|
||||
news: News[] = [];
|
||||
constructor(private router: Router) {
|
||||
$.ajax({
|
||||
url: 'https://localhost/web/Lab%208/BackEnd/Repositories/Repository.php?action=isLogged',
|
||||
type: 'GET',
|
||||
xhrFields: {
|
||||
withCredentials: true
|
||||
},
|
||||
success: function(data: any){
|
||||
if (data === 'false'){
|
||||
router.navigate(['/login']);
|
||||
}
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
context: this,
|
||||
url: 'https://localhost/web/Lab%208/BackEnd/Repositories/Repository.php?action=getAllNews',
|
||||
type: 'GET',
|
||||
xhrFields: {
|
||||
withCredentials: true
|
||||
},
|
||||
success: function(data: any){
|
||||
this.news = JSON.parse(data);
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
logout = () => {
|
||||
let router = this.router;
|
||||
$.ajax({
|
||||
url: 'https://localhost/web/Lab%208/BackEnd/Repositories/Repository.php?action=logout',
|
||||
type: 'GET',
|
||||
xhrFields: {
|
||||
withCredentials: true
|
||||
},
|
||||
success: function(data: any){
|
||||
router.navigate(['/login']);
|
||||
}
|
||||
});
|
||||
}
|
||||
addNews = () => {
|
||||
this.router.navigate(['/add']);
|
||||
}
|
||||
editNews = (id: number) => {
|
||||
this.router.navigate([`/edit/${id}`]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user