Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. class Uczen {
  2. public Imie: string;
  3. public Nazwisko: string;
  4. public Oceny: Array<Oceny>;
  5. public Row: JQuery;
  6. }
  7. class Oceny {
  8. public Przedmiot: string;
  9. public Ocena: number;
  10. }
  11.  
  12.  
  13. class GradeTable implements IContent {
  14. private UI: { table: JQuery, tHead: JQuery, tBody: JQuery, rows: Array<JQuery> } = { table: null, tHead: null, tBody: null, rows: [] };
  15. constructor(uczen: Uczen) {
  16. this.Prepare();
  17. this.buildBasics();
  18. this.AddRows(uczen);
  19. }
  20. public GetBody(): JQuery {
  21.  
  22. return this.UI.table;
  23. }
  24.  
  25. private Prepare(): void {
  26. this.UI.table = $('<table class="table">');
  27. this.UI.tHead = $('<thead>' +
  28. '<tr>' +
  29. '<th>#</th>' +
  30. '<th>Przedmiot</th>' +
  31. '<th>Ocena</th>' +
  32. '</tr>' +
  33. '</thead>');
  34. this.UI.tBody = $('<tbody>');
  35.  
  36. }
  37. private buildBasics(): void {
  38. this.UI.table.append(this.UI.tHead);
  39. this.UI.table.append(this.UI.tBody);
  40.  
  41. }
  42. private AddRows(uczen: Uczen): void {
  43. let nr: number = 1;
  44. for (var gradeS of uczen.Oceny) {
  45.  
  46. let row: JQuery = $('<tr>');
  47. let nrOfRow: JQuery = $('<th scope="row">' + nr + '</th>');
  48. let przedmiot: JQuery = $('<td>' + gradeS.Przedmiot + '</td>');
  49. let grade: JQuery = $('<td>' + gradeS.Ocena + '</td>');
  50. row.append(nrOfRow, przedmiot, grade);
  51. this.UI.rows.push(row);
  52. this.UI.tBody.append(row);
  53. this.UI.table
  54.  
  55. nr++;
  56. }
  57.  
  58. }
  59.  
  60. } // do ModalWindow
  61.  
  62. class Dziennik {
  63.  
  64. private placeholder: JQuery;
  65. private title: string='Tytuł';
  66. private headerTitle: string='TekstHeadera';
  67. private uczniowie: Array<Uczen> = null;
  68. private UI: { gradeBook: JQuery, panelDefault: JQuery, panelHeading: JQuery, panelBody: JQuery, table: JQuery, tHead: JQuery, tBody: JQuery, rows: Array<JQuery>, textField: JQuery } = { gradeBook: null, panelDefault: null, panelHeading: null, panelBody: null, table: null, tHead: null, tBody: null, rows: [], textField:null };
  69.  
  70.  
  71.  
  72.  
  73.  
  74. constructor(placeholder: JQuery, title: string, headerTitle: string, uczniowie: Array<Uczen>) {
  75. //init
  76. this.placeholder = placeholder;
  77. this.title = title;
  78. this.headerTitle = headerTitle;
  79. this.uczniowie = uczniowie;
  80. this.Prepare();
  81. this.BuildBasics();
  82. this.AddRowsToTable(this.uczniowie);
  83. }
  84.  
  85. public Render(): void {
  86. $(this.placeholder).append(this.UI.gradeBook);
  87.  
  88. }
  89.  
  90. private Prepare(): void {
  91.  
  92. this.UI.gradeBook = $('<div>');
  93. //panel start
  94. this.UI.panelDefault = $('<div class="panel panel-default">');
  95.  
  96.  
  97. this.UI.panelHeading = $('<div class="panel-heading" > ' + this.title + '</div>');
  98. this.UI.panelBody = $('<div class="panel-body">' + this.headerTitle + '</div>');
  99. //panel end
  100.  
  101. //table start
  102. this.UI.table = $('<table class="table">');
  103. this.UI.tHead = $('<thead>'+
  104. '<tr>'+
  105. '<th>#</th>'+
  106. '<th>Nazwisko</th>'+
  107. '<th>Imię</th>'+
  108. '<th>Średnia</th>'+
  109. '</tr>'+
  110. '</thead>');
  111. this.UI.tBody = $('<tbody>');
  112.  
  113. //table end
  114. //textfiled
  115. this.UI.textField = $('<input type="text" name="search">');
  116. this.UI.textField.keyup(() => {
  117. console.log(this.UI.textField);
  118. this.searchInList(this.UI.textField.val());
  119. })
  120.  
  121. }
  122. private searchInList(text: string): void {
  123. if (text != '') {
  124. $('td').parent().hide();
  125. $('td:contains(' + text + ')').parent().show();
  126. }
  127. else $('td').parent().show();
  128. }
  129. private BuildBasics(): void{
  130. //panelStart
  131. this.UI.panelDefault.append(this.UI.panelHeading);
  132. this.UI.panelDefault.append(this.UI.panelBody);
  133. //panelEnd
  134.  
  135. //tableStart
  136. this.UI.table.append(this.UI.tHead);
  137. this.UI.table.append(this.UI.tBody);
  138. //tableEnd
  139. this.UI.gradeBook.append(this.UI.panelDefault, this.UI.table, this.UI.textField);
  140.  
  141.  
  142. }
  143.  
  144. private AddRowsToTable(uczniowie: Array<Uczen>): void {
  145.  
  146. let nr: number = 1;
  147.  
  148. for (var uczen of uczniowie) {
  149.  
  150. let row: JQuery = $('<tr>');
  151. let nrOfRow: JQuery = $('<th scope="row">' + nr + '</th>');
  152. let name: JQuery = $('<td>' + uczen.Imie + '</td>');
  153. let sureName: JQuery = $('<td>' + uczen.Nazwisko + '</td>');
  154. let averageGrade: JQuery = $('<td>' + this.CountAverageGrade(uczen) + '<a> szczegóły--&gt;</a></td>');
  155. let actualName: string = uczen.Imie + ' ' + uczen.Nazwisko;
  156. let ActualUczen: Uczen = uczen;
  157. averageGrade.click(() => {
  158. var gradeWindow = new CustomModal(TypeEnum.Choice, ThemeEnum.Warning, 'Oceny ucznia ' + actualName, new GradeTable(ActualUczen), null);
  159. gradeWindow.Render();
  160.  
  161.  
  162. });
  163.  
  164. row.append(nrOfRow, name, sureName, averageGrade);
  165. this.UI.rows.push(row);
  166. this.UI.tBody.append(row);
  167.  
  168.  
  169. nr++;
  170. }
  171.  
  172. }
  173.  
  174. private CountAverageGrade(uczen: Uczen) :number {
  175. let avrGrade: number = 0;
  176. for (var ocena of uczen.Oceny) {
  177. avrGrade += ocena.Ocena;
  178. }
  179. return avrGrade / uczen.Oceny.length;
  180. }
  181. }
  182.  
  183.  
  184.  
  185. window.onload = () => {
  186.  
  187. var dane = [{ "Imie": "Marek", "Nazwisko": "Mazur", "Oceny": [{ "Przedmiot": "Polski", "Ocena": 2 }, { "Przedmiot": "Matematyka", "Ocena": 5 }] }, { "Imie": "Artur", "Nazwisko": "Brennek", "Oceny": [{ "Przedmiot": "Polski", "Ocena": 5 }, { "Przedmiot": "Matematyka", "Ocena": 3 }] }, { "Imie": "Dorota", "Nazwisko": "Brennek", "Oceny": [{ "Przedmiot": "Polski", "Ocena": 5 }, { "Przedmiot": "Matematyka", "Ocena": 5 }] }];
  188.  
  189.  
  190. var firstGradeBook = new Dziennik($('body'), 'Dzienniczek ucznia', 'Klasa 6b', <Array<Uczen>>dane);
  191.  
  192. firstGradeBook.Render();
  193.  
  194. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement