Commit 7518dedf authored by achinta's avatar achinta

feat: assignment add and delete

parent df9761a5
......@@ -3,6 +3,7 @@ import { UserProfile } from '../interface/user-profile';
import { isPlatformBrowser } from '@angular/common';
import { Router } from '@angular/router';
import { RequestMapperService } from '../../mappers/request-mapper.service';
import { LogoutService } from '../../portal/navigation/service/logout.service';
@Injectable({
providedIn: 'root'
......@@ -12,8 +13,10 @@ export class AuthService {
public isBrowser: boolean = false;
constructor(
@Inject(PLATFORM_ID) private _platformId: Object,
private _router: Router,
@Inject(PLATFORM_ID) private _platformId: Object) {
private _logout: LogoutService,
) {
this.isBrowser = isPlatformBrowser(this._platformId);
}
......
......@@ -8,6 +8,4 @@
<input type="text" readonly matInput [value]="fileName" />
<input type="file" multiple #f_input (change)="onFileSelected($event)" hidden />
<mat-error *ngIf="!selectedFiles().length">This field is required</mat-error>
</mat-form-field>
\ No newline at end of file
......@@ -23,12 +23,15 @@ export class FileInputComponent {
// Triggered when files are selected
onFileSelected(event: Event): void {
const input = event.target as HTMLInputElement;
if (input.files) {
this.selectedFiles.set(Array.from(input.files)); // Update the signal
this.filesChange.emit(this.selectedFiles()); // Emit the event
console.log(input.files[0].name);
this.fileName = input.files[0].name
}
}
......
......@@ -26,6 +26,9 @@ export class TransmissionMapperService {
public static readonly FILE_UPLOAD_TRANSMISSION_URL: string =
TransmissionMapperService.DEV_TRANSMISSION_URL + '/webomagic/uploadFile?';
public static readonly DELETE_RECORD_TRANSMISSION_URL: string =
TransmissionMapperService.DEV_TRANSMISSION_URL + '/webomagic/deleteWebsiteDataSourceFieldsBasedOnDataSourceType?';
// aggregationOnUniqueFld=false&datasourceId=3188&dontIncludeForeignKey=false&expand=false&isUniqueValueRequiredForFieldToDisplay=false&language=en&limit=10&orderBy=ASC&page=1&user_id=206&roleBasedFiltering=true
// public static readonly SCHEDULE_OF_RATES_TRANSMISSION_URL: string =
// TransmissionMapperService.DEV_TRANSMISSION_URL +
......
......@@ -12,6 +12,10 @@ import { PrepareAssignmentTableDataService } from '../service/prepare-assignment
import { DataSourceService } from '../../service/data-source.service';
import { AuthService } from '../../../auth/service/auth.service';
import { CommonModule } from '@angular/common';
import { RaintreeResponse } from '../../../raintree/interface/raintree-response';
import { MatDialogConfigService } from '../../service/mat-dialog-config.service';
import { DeleteRecordTransmissionService } from '../../../raintree/transmission/delete-record-transmission.service';
import { ToasterService } from '../../../component-library/toaster/toaster.service';
@Component({
selector: 'app-assignment',
......@@ -30,10 +34,13 @@ export class AssignmentComponent implements OnInit {
private _assignmentTransmission: AssignmentTransmissionService,
private _urlConfig: UrlConfigService,
private _prepareAssignmentTableData: PrepareAssignmentTableDataService,
public authService: AuthService
public matConfig: MatDialogConfigService,
public authService: AuthService,
private _deleteTransmission:DeleteRecordTransmissionService,
private _toaster:ToasterService
) { }
public columns:any[] = [];
public columns: any[] = [];
public data: any[] = [];
......@@ -60,10 +67,10 @@ export class AssignmentComponent implements OnInit {
}),
() => { },
(response) => { },
(response: AssignmentsResponse) => {
(response: RaintreeResponse) => {
this.data = this._prepareAssignmentTableData.prepareMatTableData(
response.data.themeDataSourceFields
response['data'].themeDataSourceFields
);
},
(error) => {
......@@ -73,33 +80,41 @@ export class AssignmentComponent implements OnInit {
)
}
public emitViewFromTable(clickedData: string): void {
alert("Have to view the doc in another page");
public emitViewFromTable(emitData: any): void {
let docLink = emitData.document.replace('BASE_URL', TransmissionMapperService.DEV_TRANSMISSION_URL);
window.open(docLink, '_blank');
}
public emitDeleteFromTable(emitData: string): void {
public emitDeleteFromTable(emitData: any): void {
if (!confirm("Are you sure to delete ?")) return;
// this._dialog.open(ManageComponent, {
// data: emitData,
// width: '98vw',
// height: 'auto',
// maxWidth: '70vw',
// maxHeight: '70vh',
// });
this._deleteTransmission.deleteRecord(
TransmissionMapperService.DELETE_RECORD_TRANSMISSION_URL + this._urlConfig.generateDatasourceConfigUrl({
dataSourceFieldId: `${emitData.id}`,
themeDataSourceId: DataSourceService.ASSIGNMENT_DATA_SOURCE_ID,
}),
alert("Have to Delete ");
() => { },
(response) => { },
(response: RaintreeResponse) => {
this._toaster.success("Exam schedule is deleted successfully", 'ok');
this._getAssignments();
},
(error) => {
console.log(error);
},
() => { }
)
}
public addAssignment(): void {
// alert("hi")
this._dialog.open(ManageComponent, {
data: '',
width: '98vw',
height: 'auto',
maxWidth: '70vw',
maxHeight: '70vh',
...this.matConfig
});
}
......
......@@ -4,21 +4,22 @@ import { LocalizedField } from "../../data-source/interface/localizedField";
// ThemeDataSourceField Interface
export interface Assignments extends Data {
themeDataSourceFields: Assignment[];
dataSourceTypeFieldsList?: Assignment[]
}
// ThemeDataSourceField Interface
export interface Assignment {
session: LocalizedField;
id: string;
session?: LocalizedField;
subject: LocalizedField;
assigned_on: LocalizedField;
last_submission_date: LocalizedField;
section: LocalizedField;
docs: LocalizedField;
class_subject: LocalizedField;
session_session_name: LocalizedField;
section_details: LocalizedField;
id: string;
subject_subject_name: LocalizedField;
class_subject_subject_txt: LocalizedField;
session_session_name?: LocalizedField;
section_details?: LocalizedField;
subject_subject_name?: LocalizedField;
class_subject_subject_txt?: LocalizedField;
}
<pre>{{ data | json }}</pre>
<!-- <h1> Hi Manage </h1> -->
<div class="container">
<form class="routine_form" [formGroup]="assignmentForm">
<div class="mat_input_container">
<!-- <div class="class_dropdown mat_input">
<mat-form-field class="full_width">
<mat-label>Select Class</mat-label>
<mat-select formControlName="class">
@for (class of classDropDownData; track class) {
<mat-option [value]="class.value">{{class.name}}</mat-option>
}
</mat-select>
<mat-error>This field is required</mat-error>
</mat-form-field>
</div> -->
<div class="section_dropdown mat_input">
<mat-form-field class="full_width">
<mat-label>Select Section</mat-label>
<mat-select formControlName="section">
@for (section of sectionDropDownData; track section) {
<mat-option [value]="section.value">{{section.name}}</mat-option>
}
</mat-select>
<mat-error>This field is required</mat-error>
</mat-form-field>
</div>
<div class="subject_dropdown mat_input">
<mat-form-field class="full_width">
<mat-label>Select Subject</mat-label>
<mat-select formControlName="subject">
@for (subject of subjectDropDownData; track subject) {
<mat-option [value]="subject.value">{{subject.name}}</mat-option>
}
</mat-select>
<mat-error>This field is required</mat-error>
</mat-form-field>
</div>
<div class="date_picker mat_input">
<mat-form-field class="full_width" >
<mat-label>Choose a date</mat-label>
<input matInput [matDatepicker]="picker" formControlName="lastDate" />
<mat-hint>MM/DD/YYYY</mat-hint>
<mat-datepicker-toggle matIconSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
</div>
<div class="file_upload mat_input">
<app-file-input [label]="'Upload Document'" (filesChange)="onFilesChanged($event)" />
<mat-error *ngIf="!assignmentForm.value.document">This field is required</mat-error>
</div>
</div>
<div class="add_btn">
<app-square-button [buttonIcon]="''" [buttonText]="'submit'" (emitSquareButtonClick)="submitAssignment()" />
</div>
</form>
</div>
\ No newline at end of file
.container{
padding: 10px;
}
.add_btn{
float: right;
}
.mat_input{
margin-bottom: 5px;
}
import { CommonModule } from '@angular/common';
import { CommonModule, DatePipe } from '@angular/common';
import { Component, Inject } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatSelectModule } from '@angular/material/select';
import { FileInputComponent } from '../../../component-library/file-input/file-input.component';
import { SquareButtonComponent } from '../../../component-library/square-button/square-button.component';
import { Dropdown } from '../../../component-library/dropdown/interface/dropdown';
import { FileUploadTransmissionService } from '../../../raintree/transmission/file-upload-transmission.service';
import { TransmissionMapperService } from '../../../mappers/transmission-mapper.service';
import { AuthService } from '../../../auth/service/auth.service';
import { RaintreeResponse } from '../../../raintree/interface/raintree-response';
import { ToasterService } from '../../../component-library/toaster/toaster.service';
import { AssignmentTransmissionService } from '../../../raintree/transmission/assignment-transmission.service';
import { ClassTransmissionService } from '../../../raintree/transmission/class-transmission.service';
import { UrlConfigService } from '../../service/url-config.service';
import { DataSourceService } from '../../service/data-source.service';
import { StudentSection } from '../../data-source/interface/section';
import { Assignments } from '../interface/assignment';
import { subject } from '../../data-source/interface/subject';
import {MatDatepickerModule} from '@angular/material/datepicker';
import {MatNativeDateModule, provideNativeDateAdapter} from '@angular/material/core';
import { MatInputModule } from '@angular/material/input';
@Component({
selector: 'app-manage',
imports: [CommonModule],
imports: [
CommonModule,
MatIconModule,
MatFormFieldModule,
MatSelectModule,
ReactiveFormsModule,
FileInputComponent,
MatDatepickerModule,
MatInputModule,
SquareButtonComponent,
MatNativeDateModule,
],
standalone: true,
providers: [provideNativeDateAdapter(),DatePipe],
templateUrl: './manage.component.html',
styleUrl: './manage.component.scss'
styleUrls: ['./manage.component.scss'],
})
export class ManageComponent {
constructor(
@Inject(MAT_DIALOG_DATA) public data: any,
){}
private _fileUpload: FileUploadTransmissionService,
private _auth: AuthService,
private _assignmentTransmission: AssignmentTransmissionService,
private _classTransmission: ClassTransmissionService,
private _urlConfig: UrlConfigService,
private _toaster: ToasterService,
private _datePipe:DatePipe
) { }
// public classDropDownData: Dropdown[] = [];
public subjectDropDownData: Dropdown[] = [];
public sectionDropDownData: Dropdown[] = [];
public assignmentForm = new FormGroup({
// class: new FormControl("", [Validators.required]),
section: new FormControl("", [Validators.required]),
subject: new FormControl("", [Validators.required]),
lastDate: new FormControl("", [Validators.required]),
document: new FormControl(""),
});
ngOnInit(): void {
// this._getClasses();
this._getSection();
this._getSubject();
}
public onFilesChanged(files: File[]): void {
const formData = new FormData();
files.forEach(file => formData.append('file', file, file.name));
this._fileUpload.uploadFile(
TransmissionMapperService.FILE_UPLOAD_TRANSMISSION_URL + `websiteId=${this._auth.localStorageGetItemByKey('project_id')}`,
formData,
() => { },
() => { },
(response: RaintreeResponse) => {
this.assignmentForm.value.document = `${TransmissionMapperService.DEV_TRANSMISSION_URL}/webomagic/getFile?fid=${response['data']}`
this._toaster.success(response.message, 'Ok')
},
(error) => {
console.log(error);
},
() => { }
)
}
public submitAssignment(): void {
// console.log(this._prepareAddAssignmentPayload());
// return
if (this.assignmentForm.invalid) return;
this._assignmentTransmission.addAssignment(
TransmissionMapperService.SAVE_TRANSMISSION_URL + `websiteId=${this._auth.localStorageGetItemByKey('project_id')}`,
this._prepareAddAssignmentPayload(),
() => { },
() => { },
(response: RaintreeResponse) => {
this._toaster.success("Assignment added successfully", 'Done');
window.location.reload();
},
(error) => {
console.log(error);
},
() => { }
);
}
// private _getClasses() {
// this._classTransmission.getClasses(
// TransmissionMapperService.GET_TRANSMISSION_URL +
// this._urlConfig.generateDatasourceConfigUrl({
// aggregationOnUniqueFld: false,
// datasourceId: DataSourceService.CLASS_DATA_SOURCE_ID,
// dontIncludeForeignKey: false,
// expand: false,
// isUniqueValueRequiredForFieldToDisplay: false,
// language: "en",
// limit: 100,
// orderBy: "ASC",
// page: 1,
// roleBasedFiltering: true,
// }),
// () => { },
// (response) => { },
// (response: classResponse) => {
// this.classDropDownData = response.data["themeDataSourceFields"].map(
// (sClass: StudentClass) => {
// return {
// ["name"]: sClass.details["en"],
// ["value"]: sClass.id,
// };
// }
// );
// },
// (error) => {
// console.log(error);
// },
// () => { }
// );
// }
private _getSubject() {
this._classTransmission.getSubject(
TransmissionMapperService.GET_TRANSMISSION_URL +
this._urlConfig.generateDatasourceConfigUrl({
aggregationOnUniqueFld:false,
datasourceId: DataSourceService.SUBJECT_DATA_SOURCE_ID,
dontIncludeForeignKey:false,
expand:false,
isUniqueValueRequiredForFieldToDisplay:false,
language:"en",
limit:100,
orderBy:"ASC",
page:1,
}),
() => { },
(response) => { },
(response: RaintreeResponse) => {
this.subjectDropDownData = response['data']["themeDataSourceFields"].map(
(sSubject: subject) => {
return {
["name"]: sSubject.subject_name["en"],
["value"]: sSubject.id,
};
}
);
},
(error) => {
console.log(error);
},
() => { }
);
}
private _getSection() {
this._classTransmission.getSection(
TransmissionMapperService.GET_TRANSMISSION_URL +
this._urlConfig.generateDatasourceConfigUrl({
aggregationOnUniqueFld: false,
datasourceId: DataSourceService.SECTION_DATA_SOURCE_ID,
dontIncludeForeignKey: false,
expand: false,
isUniqueValueRequiredForFieldToDisplay: false,
language: "en",
limit: 100,
orderBy: "ASC",
page: 1,
roleBasedFiltering: true,
}),
() => { },
(response) => { },
(response: RaintreeResponse) => {
this.sectionDropDownData = response['data']["themeDataSourceFields"].map(
(sSection: StudentSection) => {
return {
["name"]: sSection.section["en"],
["value"]: sSection.id,
};
}
);
},
(error) => {
console.log(error);
},
() => { }
);
}
private _prepareAddAssignmentPayload(): Assignments {
return {
themeDataSourceFields: [
{
id: "",
section: {
en: `${this.assignmentForm.value.section}`,
beng: `${this.assignmentForm.value.section}`,
hindi: `${this.assignmentForm.value.section}`,
},
class_subject: {
en: ``,
beng: ``,
hindi: ``,
},
assigned_on: {
en: "",
beng: "",
hindi: "",
},
last_submission_date: {
en: `${this._datePipe.transform(this.assignmentForm.value.lastDate,'yyyy-MM-dd')}`,
beng: `${this._datePipe.transform(this.assignmentForm.value.lastDate,'yyyy-MM-dd')}`,
hindi: `${this._datePipe.transform(this.assignmentForm.value.lastDate,'yyyy-MM-dd')}`,
},
docs: {
en: `${this.assignmentForm.value.document}`,
beng: `${this.assignmentForm.value.document}`,
hindi: `${this.assignmentForm.value.document}`,
},
subject: {
en: `${this.assignmentForm.value.subject}`,
beng: `${this.assignmentForm.value.subject}`,
hindi: `${this.assignmentForm.value.subject}`,
},
},
],
dataSourceName: DataSourceService.ASSIGNMENT_DATA_SOURCE_NAME,
id: `${DataSourceService.ASSIGNMENT_DATA_SOURCE_ID}`,
type: `${DataSourceService.ASSIGNMENT_DATA_SOURCE_TYPE}`,
themeId: `${this._auth.localStorageGetItemByKey('project_id')}`,
slideLst: null,
heading: "undefined",
dataSourceTypeFieldsList: [
{
id: "",
section: {
en: `${this.assignmentForm.value.section}`,
beng: `${this.assignmentForm.value.section}`,
hindi: `${this.assignmentForm.value.section}`,
},
class_subject: {
en: ``,
beng: ``,
hindi: ``,
},
assigned_on: {
en: "",
beng: "",
hindi: "",
},
last_submission_date: {
en: `${this._datePipe.transform(this.assignmentForm.value.lastDate,'yyyy-MM-dd')}`,
beng: `${this._datePipe.transform(this.assignmentForm.value.lastDate,'yyyy-MM-dd')}`,
hindi: `${this._datePipe.transform(this.assignmentForm.value.lastDate,'yyyy-MM-dd')}`,
},
docs: {
en: `${this.assignmentForm.value.document}`,
beng: `${this.assignmentForm.value.document}`,
hindi: `${this.assignmentForm.value.document}`,
},
subject: {
en: `${this.assignmentForm.value.subject}`,
beng: `${this.assignmentForm.value.subject}`,
hindi: `${this.assignmentForm.value.subject}`,
},
},
],
count: 0,
favourite: true
};
}
}
......@@ -14,10 +14,12 @@ export class PrepareAssignmentTableDataService {
return {
['id']: assignment.id,
['subject']: assignment.class_subject_subject_txt['en'],
['section_details']: assignment.section_details['en'],
['session_name']: assignment.session_session_name['en'],
['assigned_on']: assignment.assigned_on['en'],
['subject']: assignment.subject_subject_name?.en,
['section_details']: assignment.section_details?.en,
['session_name']: assignment.session_session_name?.en,
['assigned_on']: assignment.assigned_on?.en,
['last_date']: assignment.last_submission_date['en'],
['document']: assignment.docs['en'],
['action']: ['view', 'delete']
}
})
......@@ -29,9 +31,9 @@ export class PrepareAssignmentTableDataService {
public prepareMatTableColumn(): any[] {
let columnArray = [
{ key: 'section_details', label: 'Class' },
{ key: 'section_details', label: 'Section' },
{ key: 'subject', label: 'Subject' },
{ key: 'assigned_on', label: 'Date' },
{ key: 'last_date', label: 'Last Date' },
{ key: 'action', label: 'Action' },
];
......
......@@ -2,7 +2,7 @@ import { ForeignKeyMap } from "./foreignKeyMap";
// Data Interface
export interface Data {
count: number;
count?: number;
id: number | string;
dataSourceName: string;
websiteId?: number;
......@@ -10,7 +10,7 @@ export interface Data {
foreignKeyMapping?: any;
foreignKeyMap?: ForeignKeyMap;
requiredPresentationField?: string;
favourite: boolean;
favourite?: boolean;
icon?: string;
dependentFields?: any;
dsType?: any;
......
import { Data } from "./data";
import { LocalizedField } from "./localizedField";
// ThemeDataSourceField Interface
export interface Subjects extends Data {
themeDataSourceFields: subject[];
}
// ThemeDataSourceField Interface
export interface subject {
id: string;
subject_name: LocalizedField;
}
......@@ -12,6 +12,9 @@ import { PrepareExamTableDataService } from '../service/prepare-exam-table-data.
import { RaintreeResponse } from '../../../raintree/interface/raintree-response';
import { AuthService } from '../../../auth/service/auth.service';
import { MatDialogConfigService } from '../../service/mat-dialog-config.service';
import { DeleteRecordTransmissionService } from '../../../raintree/transmission/delete-record-transmission.service';
import { ExamTable } from '../interface/exam-table';
import { ToasterService } from '../../../component-library/toaster/toaster.service';
@Component({
selector: 'app-exam',
......@@ -27,11 +30,13 @@ export class ExamComponent {
constructor(
private _dialog: MatDialog,
private _examSchedule:ExamScheduleService,
private _examSchedule: ExamScheduleService,
private _urlConfig: UrlConfigService,
private _prepareExamTableData: PrepareExamTableDataService,
private _matDialogConfig: MatDialogConfigService,
public authService:AuthService
private _deleteTransmission: DeleteRecordTransmissionService,
public _toaster:ToasterService,
public authService: AuthService
) { }
public columns: any = [];
......@@ -50,9 +55,28 @@ export class ExamComponent {
window.open(docLink, '_blank');
}
public emitDeleteFromTable(emitData: string): void {
public emitDeleteFromTable(emitData: any): void {
alert("Should delete !!")
if(!confirm("Are you sure to delete ?")) return;
this._deleteTransmission.deleteRecord(
TransmissionMapperService.DELETE_RECORD_TRANSMISSION_URL + this._urlConfig.generateDatasourceConfigUrl({
dataSourceFieldId:`${emitData.id}`,
themeDataSourceId: DataSourceService.EXAM_SCHEDULE_DATA_SOURCE_ID,
}),
() => { },
(response) => { },
(response: RaintreeResponse) => {
this._toaster.success("Exam schedule is deleted successfully", 'ok');
this._getExamSchedule();
},
(error) => {
console.log(error);
},
() => { }
)
}
......
......@@ -6,6 +6,8 @@ import { LocalizedField } from "../../data-source/interface/localizedField";
export interface ExamSchedules extends Data {
themeDataSourceFields: ExamSchedule[];
dataSourceTypeFieldsList?: ExamSchedule[]
}
// ThemeDataSourceField Interface
......@@ -16,7 +18,7 @@ export interface ExamSchedule {
image: LocalizedField;
details: LocalizedField;
class: LocalizedField;
session_session_name: LocalizedField;
class_details: LocalizedField;
session_session_name?: LocalizedField;
class_details?: LocalizedField;
}
export interface ExamTable {
id:string;
class_details?: string,
details: string;
term: string;
image: string;
action: string[]
}
\ No newline at end of file
<pre> {{data|json}} </pre>
\ No newline at end of file
<!-- <h1> Hi Manage </h1> -->
<div class="container">
<form class="routine_form" [formGroup]="examScheduleForm">
<div class="mat_input_container">
<div class="class_dropdown mat_input">
<mat-form-field class="full_width">
<mat-label>Select Class</mat-label>
<mat-select formControlName="class">
@for (class of classDropDownData; track class) {
<mat-option [value]="class.value">{{class.name}}</mat-option>
}
</mat-select>
<mat-error>This field is required</mat-error>
</mat-form-field>
</div>
<div class="section_dropdown mat_input">
<mat-form-field class="full_width">
<mat-label>Select Term</mat-label>
<mat-select formControlName="term">
<mat-option value="First term">First term</mat-option>
<mat-option value="Last term">Last term</mat-option>
</mat-select>
<mat-error>This field is required</mat-error>
</mat-form-field>
</div>
<div class="details_input mat_input">
<mat-form-field class="full_width">
<mat-label>Details</mat-label>
<input
matInput
placeholder="Details"
#input
formControlName="details"
/>
<mat-error>This field is required</mat-error>
</mat-form-field>
</div>
<div class="file_upload mat_input">
<app-file-input [label]="'Upload Document'" (filesChange)="onFilesChanged($event)" />
<mat-error *ngIf="!examScheduleForm.value.document" >This field is required</mat-error>
</div>
</div>
<div class="add_btn">
<app-square-button [buttonIcon]="''" [buttonText]="'submit'" (emitSquareButtonClick)="submitExamSchedule()" />
</div>
</form>
</div>
\ No newline at end of file
.container{
padding: 10px;
}
.add_btn{
float: right;
}
.mat_input{
margin-bottom: 5px;
}
import { CommonModule } from '@angular/common';
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { CommonModule } from "@angular/common";
import { Component, Inject, OnInit } from "@angular/core";
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from "@angular/forms";
import { MAT_DIALOG_DATA } from "@angular/material/dialog";
import { MatInputModule } from "@angular/material/input";
import { MatSelectModule } from "@angular/material/select";
import { FileInputComponent } from "../../../component-library/file-input/file-input.component";
import { SquareButtonComponent } from "../../../component-library/square-button/square-button.component";
import { FileUploadTransmissionService } from "../../../raintree/transmission/file-upload-transmission.service";
import { TransmissionMapperService } from "../../../mappers/transmission-mapper.service";
import { AuthService } from "../../../auth/service/auth.service";
import { RaintreeResponse } from "../../../raintree/interface/raintree-response";
import { ClassTransmissionService } from "../../../raintree/transmission/class-transmission.service";
import { UrlConfigService } from "../../service/url-config.service";
import { DataSourceService } from "../../service/data-source.service";
import { classResponse } from "../../../raintree/interface/class-respons";
import { Dropdown } from "../../../component-library/dropdown/interface/dropdown";
import { StudentClass } from "../../data-source/interface/class";
import { ExamScheduleService } from "../../../raintree/transmission/exam-schedule.service";
import { ToasterService } from "../../../component-library/toaster/toaster.service";
import { ExamSchedules } from "../interface/exam-schedule";
@Component({
selector: 'app-manage',
selector: "app-manage",
imports: [
CommonModule
CommonModule,
MatInputModule,
MatSelectModule,
ReactiveFormsModule,
FileInputComponent,
SquareButtonComponent,
],
templateUrl: './manage.component.html',
styleUrl: './manage.component.scss'
templateUrl: "./manage.component.html",
styleUrl: "./manage.component.scss",
})
export class ManageComponent {
constructor(
@Inject(MAT_DIALOG_DATA) public data: any,
private _fileUpload: FileUploadTransmissionService,
private _auth: AuthService,
private _classTransmission: ClassTransmissionService,
private _urlConfig: UrlConfigService,
private _examScheduleTransmission: ExamScheduleService,
public toaster: ToasterService
) { }
public classDropDownData: Dropdown[] = [];
public examScheduleForm = new FormGroup({
class: new FormControl("", [Validators.required]),
term: new FormControl("", [Validators.required]),
details: new FormControl("", [Validators.required]),
document: new FormControl("", [Validators.required]),
});
public ngOnInit(): void {
this._getClasses();
}
public onFilesChanged(files: File[]): void {
const formData = new FormData();
files.forEach(file => formData.append('file', file, file.name));
this._fileUpload.uploadFile(
TransmissionMapperService.FILE_UPLOAD_TRANSMISSION_URL + `websiteId=${this._auth.localStorageGetItemByKey('project_id')}`,
formData,
() => { },
() => { },
(response: RaintreeResponse) => {
this.examScheduleForm.value.document = `${TransmissionMapperService.DEV_TRANSMISSION_URL}/webomagic/getFile?fid=${response['data']}`
this.toaster.success(response.message,'Ok')
},
(error) => {
console.log(error);
},
() => { }
)
}
private _getClasses() {
this._classTransmission.getClasses(
TransmissionMapperService.GET_TRANSMISSION_URL +
this._urlConfig.generateDatasourceConfigUrl({
aggregationOnUniqueFld: false,
datasourceId: DataSourceService.CLASS_DATA_SOURCE_ID,
dontIncludeForeignKey: false,
expand: false,
isUniqueValueRequiredForFieldToDisplay: false,
language: "en",
limit: 100,
orderBy: "ASC",
page: 1,
roleBasedFiltering: true,
}),
() => { },
(response) => { },
(response: RaintreeResponse) => {
this.classDropDownData = response['data']["themeDataSourceFields"].map(
(sClass: StudentClass) => {
return {
["name"]: sClass.details["en"],
["value"]: sClass.id,
};
}
);
},
(error) => {
console.log(error);
},
() => { }
);
}
public submitExamSchedule(): void {
if (this.examScheduleForm.invalid) return;
this._examScheduleTransmission.addExamSchedule(
TransmissionMapperService.SAVE_TRANSMISSION_URL + `websiteId=${this._auth.localStorageGetItemByKey('project_id')}`,
this._prepareExamSchedulePayload(),
() => { },
() => { },
(response: RaintreeResponse) => {
this.toaster.success("Exam schedule added successfully", 'Done');
window.location.reload();
},
(error) => {
console.log(error);
},
() => { }
);
}
private _prepareExamSchedulePayload(): ExamSchedules {
return {
"themeDataSourceFields": [
{
"id": "",
"session": {
"en": "",
"beng": "",
"hindi": ""
},
"Term": {
"en": `${this.examScheduleForm.value.term}`,
"beng": `${this.examScheduleForm.value.term}`,
"hindi": `${this.examScheduleForm.value.term}`
},
"image": {
"en": `${this.examScheduleForm.value.document}`,
"beng": `${this.examScheduleForm.value.document}`,
"hindi": `${this.examScheduleForm.value.document}`
},
"details": {
"en": `${this.examScheduleForm.value.details}`,
"beng": `${this.examScheduleForm.value.details}`,
"hindi": `${this.examScheduleForm.value.details}`
},
"class": {
"en": `${this.examScheduleForm.value.class}`,
"beng": `${this.examScheduleForm.value.class}`,
"hindi": `${this.examScheduleForm.value.class}`
}
}
],
"dataSourceName": DataSourceService.EXAM_SCHEDULE_DATA_SOURCE_NAME,
"id": DataSourceService.EXAM_SCHEDULE_DATA_SOURCE_ID,
"type": `${DataSourceService.EXAM_SCHEDULE_DATA_SOURCE_TYPE}`,
"themeId": `${this._auth.localStorageGetItemByKey('project_id')}`,
"slideLst": null,
"heading": "undefined",
"dataSourceTypeFieldsList": [
{
"id": "",
"session": {
"en": "",
"beng": "",
"hindi": ""
},
"Term": {
"en": `${this.examScheduleForm.value.term}`,
"beng": `${this.examScheduleForm.value.term}`,
"hindi": `${this.examScheduleForm.value.term}`
},
"image": {
"en": `${this.examScheduleForm.value.document}`,
"beng": `${this.examScheduleForm.value.document}`,
"hindi": `${this.examScheduleForm.value.document}`
},
"details": {
"en": `${this.examScheduleForm.value.details}`,
"beng": `${this.examScheduleForm.value.details}`,
"hindi": `${this.examScheduleForm.value.details}`
},
"class": {
"en": `${this.examScheduleForm.value.class}`,
"beng": `${this.examScheduleForm.value.class}`,
"hindi": `${this.examScheduleForm.value.class}`
}
}
]
};
}
}
import { Injectable } from '@angular/core';
import { ExamSchedule } from '../interface/exam-schedule';
import { ExamTable } from '../interface/exam-table';
@Injectable({
providedIn: 'root'
......@@ -8,17 +9,17 @@ export class PrepareExamTableDataService {
constructor() { }
public prepareMatTableData(data: ExamSchedule[]): any {
public prepareMatTableData(data: ExamSchedule[]): ExamTable[] {
let dataArray = data.map((schedule: ExamSchedule) => {
return {
['id']: schedule.id,
['class_details']: schedule.class_details['en'],
['details']: schedule.details['en'],
['term']: schedule.Term['en'],
['image']: schedule.image['en'],
['action']: ['view', 'delete']
id: schedule.id,
class_details: schedule.class_details?.en,
details: schedule.details['en'],
term: schedule.Term['en'],
image: schedule.image['en'],
action: ['view', 'delete']
}
})
......
......@@ -64,7 +64,7 @@ export class ManageComponent {
class: new FormControl("", [Validators.required]),
section: new FormControl("", [Validators.required]),
routineType: new FormControl("", [Validators.required]),
schedule: new FormControl("", [Validators.required]),
schedule: new FormControl(""),
});
ngOnInit(): void {
......@@ -73,7 +73,6 @@ export class ManageComponent {
}
public onFilesChanged(files: File[]): void {
console.log('Selected Files:', files);
const formData = new FormData();
......@@ -90,7 +89,7 @@ export class ManageComponent {
(response: RaintreeResponse) => {
this.routineForm.value.schedule = `${TransmissionMapperService.DEV_TRANSMISSION_URL}/webomagic/getFile?fid=${response['data']}`
this._toaster.success(response.message,'Ok')
},
(error) => {
console.log(error);
......@@ -143,8 +142,8 @@ export class ManageComponent {
}),
() => {},
(response) => {},
(response: classResponse) => {
this.classDropDownData = response.data["themeDataSourceFields"].map(
(response: RaintreeResponse) => {
this.classDropDownData = response['data']["themeDataSourceFields"].map(
(sClass: StudentClass) => {
return {
["name"]: sClass.details["en"],
......@@ -177,8 +176,8 @@ export class ManageComponent {
}),
() => {},
(response) => {},
(response: SectionResponse) => {
this.sectionDropDownData = response.data["themeDataSourceFields"].map(
(response: RaintreeResponse) => {
this.sectionDropDownData = response['data']["themeDataSourceFields"].map(
(sSection: StudentSection) => {
return {
["name"]: sSection.section["en"],
......
......@@ -12,6 +12,9 @@ import { PrepareRoutineTableDataService } from '../service/prepare-routine-table
import { CommonModule } from '@angular/common';
import { AuthService } from '../../../auth/service/auth.service';
import { MatDialogConfigService } from '../../service/mat-dialog-config.service';
import { RaintreeResponse } from '../../../raintree/interface/raintree-response';
import { DeleteRecordTransmissionService } from '../../../raintree/transmission/delete-record-transmission.service';
import { ToasterService } from '../../../component-library/toaster/toaster.service';
@Component({
selector: 'app-routine',
......@@ -32,6 +35,8 @@ export class RoutineComponent {
private _dialog: MatDialog,
private _prepareRoutineTableData: PrepareRoutineTableDataService,
private _matDialogConfig: MatDialogConfigService,
private _deleteTransmission: DeleteRecordTransmissionService,
private _toaster:ToasterService,
public authService: AuthService
) { }
......@@ -58,8 +63,28 @@ export class RoutineComponent {
window.open(docLink, '_blank');
}
public emitDeleteFromTable(emitData: string): void {
alert("Should delete the data");
public emitDeleteFromTable(emitData: any): void {
if(!confirm("Are you sure to delete ?")) return;
this._deleteTransmission.deleteRecord(
TransmissionMapperService.DELETE_RECORD_TRANSMISSION_URL + this._urlConfig.generateDatasourceConfigUrl({
dataSourceFieldId:`${emitData.id}`,
themeDataSourceId: DataSourceService.ROUTINE_DATA_SOURCE_ID,
}),
() => { },
(response) => { },
(response: RaintreeResponse) => {
this._toaster.success("Routine is deleted successfully", 'ok');
this._getRoutines();
},
(error) => {
console.log(error);
},
() => { }
)
}
......@@ -79,9 +104,9 @@ export class RoutineComponent {
}),
() => { },
(response) => { },
(response: RoutineResponse) => {
(response: RaintreeResponse) => {
this.data = this._prepareRoutineTableData.prepareMatTableData(response.data.themeDataSourceFields);
this.data = this._prepareRoutineTableData.prepareMatTableData(response['data'].themeDataSourceFields);
},
(error) => {
console.log(error);
......
......@@ -6,18 +6,24 @@ import { Injectable } from '@angular/core';
export class DataSourceService {
constructor() { }
// FOR ASSIGNMENT:
public static readonly ASSIGNMENT_DATA_SOURCE_ID: number = 3188;
public static readonly ASSIGNMENT_DATA_SOURCE_NAME: string = 'Assignment';
public static readonly ASSIGNMENT_DATA_SOURCE_TYPE: number = 1330;
// FOR ROUTINE:
public static readonly ROUTINE_DATA_SOURCE_ID: number = 3021;
public static readonly ROUTINE_DATA_SOURCE_NAME: string = 'Routine';
public static readonly ROUTINE_DATA_SOURCE_TYPE: number = 1327;
// FOR EXAM SCHEDULE:
public static readonly EXAM_SCHEDULE_DATA_SOURCE_ID: number = 3018;
public static readonly EXAM_SCHEDULE_DATA_SOURCE_NAME: string = "Exam Schedule";
public static readonly EXAM_SCHEDULE_DATA_SOURCE_TYPE: number = 1329;
public static readonly CLASS_DATA_SOURCE_ID: number = 3008;
public static readonly SECTION_DATA_SOURCE_ID: number = 3013;
public static readonly EXAM_SCHEDULE_DATA_SOURCE_ID: number = 3018;
public static readonly SUBJECT_DATA_SOURCE_ID: number = 3014;
}
......@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { TransmissionService } from './transmission.service';
import { RaintreeResponse } from '../interface/raintree-response';
import { AssignmentsResponse } from '../interface/assignment-respons';
import { Assignments } from '../../portal/assignment/interface/assignment';
@Injectable({
providedIn: 'root'
......@@ -11,8 +12,8 @@ export class AssignmentTransmissionService extends TransmissionService {
public getAssignment(
url: string,
onPreExecute: () => void,
onPostExecute: (response: any) => void,
onSuccess: (response: any) => void,
onPostExecute: (response: RaintreeResponse) => void,
onSuccess: (response: RaintreeResponse) => void,
onFailure: (error: string) => void,
onComplete: () => void
): void {
......@@ -27,4 +28,25 @@ export class AssignmentTransmissionService extends TransmissionService {
true
);
}
public addAssignment(
url: string,
payload:Assignments,
onPreExecute: () => void,
onPostExecute: (response: RaintreeResponse) => void,
onSuccess: (response: RaintreeResponse) => void,
onFailure: (error: string) => void,
onComplete: () => void
){
this.executePostPayload(
url,
payload,
onPreExecute,
onPostExecute,
onSuccess,
onFailure,
onComplete,
true
);
}
}
import { Injectable } from '@angular/core';
import { TransmissionService } from './transmission.service';
import { RaintreeResponse } from '../interface/raintree-response';
@Injectable({
providedIn: 'root'
......@@ -8,8 +9,8 @@ export class ClassTransmissionService extends TransmissionService{
public getClasses(
url: string,
onPreExecute: () => void,
onPostExecute: (response: any) => void,
onSuccess: (response: any) => void,
onPostExecute: (response: RaintreeResponse) => void,
onSuccess: (response: RaintreeResponse) => void,
onFailure: (error: string) => void,
onComplete: () => void
): void {
......@@ -28,8 +29,28 @@ export class ClassTransmissionService extends TransmissionService{
public getSection(
url: string,
onPreExecute: () => void,
onPostExecute: (response: any) => void,
onSuccess: (response: any) => void,
onPostExecute: (response: RaintreeResponse) => void,
onSuccess: (response: RaintreeResponse) => void,
onFailure: (error: string) => void,
onComplete: () => void
){
this.executePostPayload(
url,
{},
onPreExecute,
onPostExecute,
onSuccess,
onFailure,
onComplete,
true
);
}
public getSubject(
url: string,
onPreExecute: () => void,
onPostExecute: (response: RaintreeResponse) => void,
onSuccess: (response: RaintreeResponse) => void,
onFailure: (error: string) => void,
onComplete: () => void
){
......
import { TestBed } from '@angular/core/testing';
import { DeleteRecordTransmissionService } from './delete-record-transmission.service';
describe('DeleteRecordTransmissionService', () => {
let service: DeleteRecordTransmissionService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(DeleteRecordTransmissionService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import { Injectable } from '@angular/core';
import { TransmissionService } from './transmission.service';
import { RaintreeResponse } from '../interface/raintree-response';
@Injectable({
providedIn: 'root'
})
export class DeleteRecordTransmissionService extends TransmissionService {
public deleteRecord(
url: string,
onPreExecute: () => void,
onPostExecute: (response: RaintreeResponse) => void,
onSuccess: (response: RaintreeResponse) => void,
onFailure: (error: string) => void,
onComplete: () => void
): void {
this.executePostPayload(
url,
{},
onPreExecute,
onPostExecute,
onSuccess,
onFailure,
onComplete,
true
);
}
}
......@@ -26,4 +26,25 @@ export class ExamScheduleService extends TransmissionService {
true
);
}
public addExamSchedule(
url: string,
payload:any,
onPreExecute: () => void,
onPostExecute: (response: any) => void,
onSuccess: (response: any) => void,
onFailure: (error: string) => void,
onComplete: () => void
){
this.executePostPayload(
url,
payload,
onPreExecute,
onPostExecute,
onSuccess,
onFailure,
onComplete,
true
);
}
}
......@@ -10,23 +10,27 @@ export class JWTService {
private _auth:AuthService
) {}
private _userId:string = this._auth.localStorageGetItemByKey('user_id');
private _authorizationToken: string = localStorage.getItem('Bearer') || '';
// private _userId:string = this._auth.localStorageGetItemByKey('user_id') ;
// private _authorizationToken: string = localStorage.getItem('Bearer') || '';
public injectToken(url: string): HttpHeaders {
// debugger;
let userId = this._auth.localStorageGetItemByKey('user_id') ;
let authorizationToken = localStorage.getItem('Bearer') || '';
return new HttpHeaders({
"user-id": this._userId,
"apikey": this._authorizationToken,
"user-id": userId,
"apikey": authorizationToken,
'Content-Type': 'application/json',
});
}
public injectTokenForFormGroupPost(url: string): HttpHeaders {
let userId = this._auth.localStorageGetItemByKey('user_id') ;
let authorizationToken = localStorage.getItem('Bearer') || '';
return new HttpHeaders({
"user-id": this._userId,
"apikey": this._authorizationToken,
"user-id": userId,
"apikey": authorizationToken,
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment