import { Component } from
"@angular/core"
;
import { CustomerService } from
"./customerservice"
;
import { Customer } from
"./customer"
;
import { MessageService } from
"primeng/api"
;
interface Book {
id: Number;
name: String;
author: String;
year: Number;
}
@Component({
selector:
"app-root"
,
templateUrl:
"./app.component.html"
,
providers: [MessageService],
styleUrls: [
"./app.component.css"
]
})
export class AppComponent {
Books: Book[] = [];
frozenCols: any[];
unlockedBooks: Book[];
lockedBooks: any[];
constructor(private customerService: CustomerService) {}
ngOnInit() {
this
.Books = [
{
id: 1001,
name:
"Clean Code"
,
author:
"Robert Cecil Martin"
,
year: 2008
},
{
id: 1002,
name:
"Introduction to Algorithms"
,
author:
"Thomas H Cormen"
,
year: 1989
},
{
id: 1003,
name:
"Refactoring"
,
author:
"Martin Fowler"
,
year: 1999
},
{
id: 1004,
name:
"Code Complete"
,
author:
"Steve McConnell"
,
year: 1993
},
{
id: 1005,
name:
"Programming Pearls"
,
author:
"John Bentley"
,
year: 1986
},
{
id: 1006,
name:
"The Clean Coder"
,
author:
"Robert Cecil Martin"
,
year: 2011
},
{
id: 1007,
name:
"Coders at Work"
,
author:
"Peter Seibel"
,
year: 2009
},
{
id: 1008,
name:
"Effective Java"
,
author:
"Joshua Bloch"
,
year: 2001
},
{
id: 1009,
name:
"Head First Java"
,
author:
"Bert Bates"
,
year: 2003
}
];
this
.unlockedBooks = [
{
id: 1001,
name:
"Clean Code"
,
author:
"Robert Cecil Martin"
,
year: 2008
},
{
id: 1002,
name:
"Introduction to Algorithms"
,
author:
"Thomas H Cormen"
,
year: 1989
},
{
id: 1003,
name:
"Refactoring"
,
author:
"Martin Fowler"
,
year: 1999
},
{
id: 1004,
name:
"Code Complete"
,
author:
"Steve McConnell"
,
year: 1993
},
{
id: 1005,
name:
"Programming Pearls"
,
author:
"John Bentley"
,
year: 1986
},
{
id: 1006,
name:
"The Clean Coder"
,
author:
"Robert Cecil Martin"
,
year: 2011
},
{
id: 1007,
name:
"Coders at Work"
,
author:
"Peter Seibel"
,
year: 2009
},
{
id: 1008,
name:
"Effective Java"
,
author:
"Joshua Bloch"
,
year: 2001
},
{
id: 1009,
name:
"Head First Java"
,
author:
"Bert Bates"
,
year: 2003
}
];
this
.lockedBooks = [
{
id: 1000,
name:
'DSA Self-Paced'
,
author:
'Sandeep Jain Sir'
,
year: 2018,
},
];
}
lockUnlock(data, frozen, index) {
if
(frozen) {
this
.lockedBooks =
this
.lockedBooks.filter((c, i) => i !== index);
this
.unlockedBooks.push(data);
}
else
{
this
.unlockedBooks =
this
.unlockedBooks.filter(
(c, i) => i !== index
);
this
.lockedBooks.push(data);
}
this
.unlockedBooks.sort((val1, val2) => {
return
val1.id < val2.id ? -1 : 1;
});
}
}