Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Table for FCFS

  • Loading branch information...
commit 8ea49617c0c19c9ce98ec850825daa88c8f7235e 1 parent 697210c
Ivov Dry ivov-dry authored
10 first_come_first_served/first_come_first_served.html
@@ -5,6 +5,7 @@
5 5 <script src="../lib/vendor/jquery-1.5.min.js" type="text/javascript"></script>
6 6 <script src="../lib/vendor/jquery.tablesorter.min.js" type="text/javascript"></script>
7 7 <script src="../lib/Process.js" type="text/javascript"></script>
  8 + <script src="../lib/ProcessTable.js" type="text/javascript"></script>
8 9 <script src="../lib/ProcessList.js" type="text/javascript"></script>
9 10 <script src="../lib/Gant.js" type="text/javascript"></script>
10 11 <script src="../lib/Time.js" type="text/javascript"></script>
@@ -25,17 +26,18 @@
25 26 <a href="../priority/priority.html">Priority</a>
26 27 </div>
27 28 <div class="clear">
28   - <table id="processes" border="1">
  29 + <b>Processes: <input id="new_process" type="button" value="New"></b>
  30 + <table id="processes" border="0">
29 31 <thead>
30 32 <tr>
31   - <th>#</th>
32 33 <th>Arrival time</th>
33 34 <th>Burst time</th>
34   - <th>Action</th>
  35 + <th></th>
35 36 </tr>
36 37 </thead>
37 38 </table>
38   - <input id="new_process" type="button" value="New Process"><input id="start" type="button" value="Start">
  39 + <input id="preview" type="button" value="Preview">
  40 + <input id="start" type="button" value="Start">
39 41 <div class="clear"></div>
40 42 <h2 class="main">
41 43 Processes:
3  lib/Process.js
@@ -4,6 +4,7 @@ var PX_PER_SECOND = 21;
4 4 var DELAY = 100;
5 5
6 6 function Process(i, arrival, burst, priority, color) {
  7 + /*
7 8 this.id = -1;
8 9
9 10 if (arrival < 0 || arrival > PROCESS_MAX_START) {
@@ -15,7 +16,7 @@ function Process(i, arrival, burst, priority, color) {
15 16 alert('Incorrect process burst time (0-' + PROCESS_MAX_START + ').');
16 17 return false;
17 18 }
18   -
  19 +*/
19 20 this.id = i;
20 21 this.burst = burst;
21 22 this.remaining_burst = burst;
43 lib/ProcessList.js
@@ -10,53 +10,24 @@ function ProcessList() {
10 10 this.max_arrival = 0;
11 11 }
12 12
13   -ProcessList.prototype.deleteRow = function(row_id) {
14   - var row_o = $('#'+ row_id)[0];
15   - row_o.parentNode.removeChild(row_o);
16   - this.refreshTable();
17   -}
18   -
19   -ProcessList.prototype.refreshTable = function() {
20   - var table_o = $('#processes')[0];
21   - var row_cnt = table_o.rows.length;
22   -
23   - for (var i = 0; i < row_cnt; i++) {
24   - console.log(table_o.rows[i].id);
25   - }
26   -}
27   -
28   -ProcessList.prototype.addNewRow = function() {
29   - var new_id = this.count + 1;
30   - var dbtn_id = 'dbtn_'+ new_id;
31   - var row_id = 'process_row_'+ new_id;
32   - var row_html = '<tr id="'+ row_id +'">';
33   - row_html += '<td id="pnr_'+ new_id +'">P'+ new_id +'</td>';
34   - row_html += '<td><input type="text" id="atime_'+ new_id +'" maxlength="5" size="5" value=""></td>';
35   - row_html += '<td><input type="text" id="btime_'+ new_id +'" maxlength="5" size="5" value=""></td>';
36   - row_html += '<td><input type="button" id="'+ dbtn_id +'" value="Delete"></td>';
37   - row_html += '</tr>';
38   - $('#processes').append(row_html);
39   - $('#'+ dbtn_id).click(function() {
40   - ProcessList.prototype.deleteRow(row_id);
41   - });
42   - this.count++;
43   - return;
  13 +ProcessList.prototype.addNew = function(arrival, burst, priority) {
  14 +/*
44 15 var arrival = parseInt(arrival, 10);
45 16 burst = parseInt(burst, 10);
46 17
47 18 if (isNaN(arrival) || isNaN(burst)) {
48 19 alert('Incorrect numbers.');
49 20 return false;
50   - }
51   -
  21 + }*/
  22 + /*
52 23 if (this.max_arrival > arrival) {
53 24 alert('Incorrect arrival time. Arrival must be >= ' + this.max_arrival);
54 25 return false;
55 26 }
56   -
  27 + */
57 28 $("h2.main").show();
58 29
59   -
  30 + var new_id = this.count + 1;
60 31 var new_color;
61 32 if (priority != undefined) {
62 33 new_color = this.colors_priority[priority - 1][new_id % this.colors_priority[priority - 1].length];
@@ -64,7 +35,7 @@ ProcessList.prototype.addNewRow = function() {
64 35 new_color = this.colors[new_id % this.colors.length];
65 36 }
66 37 var p = new Process(new_id, arrival, burst, priority, new_color);
67   - if (p.id == -1) return false;
  38 + //if (p.id == -1) return false;
68 39
69 40 this.max_arrival = arrival;
70 41 $('#ProcessList').append(p.output());
85 lib/ProcessTable.js
... ... @@ -0,0 +1,85 @@
  1 +function ProcessTable() {
  2 + this.count = 0;
  3 + this.row_id_prefix = 'process_row_';
  4 + this.arrival_input_id_prefix = 'atime_';
  5 + this.burst_input_id_prefix = 'btime_';
  6 +}
  7 +
  8 +ProcessTable.prototype.addRow = function() {
  9 + var new_id = this.count + 1;
  10 + var dbtn_id = 'dbtn_'+ new_id;
  11 + var row_id = this.row_id_prefix + new_id;
  12 + var row_html = '<tr id="'+ row_id +'">';
  13 + row_html += '<td><input type="text" class="ptime" id="'+ this.arrival_input_id_prefix + new_id +'" maxlength="5" value=""></td>';
  14 + row_html += '<td><input type="text" class="ptime" id="'+ this.burst_input_id_prefix + new_id +'" maxlength="5" value=""></td>';
  15 + row_html += '<td><input type="button" id="'+ dbtn_id +'" value="Delete"></td>';
  16 + row_html += '</tr>';
  17 + $('#processes').append(row_html);
  18 + $('#'+ dbtn_id).click(function() {
  19 + process_table.deleteRow(row_id);
  20 + });
  21 + this.count++;
  22 +}
  23 +
  24 +ProcessTable.prototype.deleteRow = function(row_id) {
  25 + var row_o = $('#'+ row_id)[0];
  26 + row_o.parentNode.removeChild(row_o);
  27 +}
  28 +
  29 +ProcessTable.prototype.proceed = function() {
  30 + var proc = [];
  31 + var tbl_o = $('#processes')[0];
  32 + var rows_cnt = tbl_o.rows.length;
  33 + var id;
  34 + var arrival;
  35 + var arrival_input;
  36 + var burst;
  37 + var burst_input;
  38 + var err;
  39 + var err_msg = {};
  40 + for (var i = 0; i < rows_cnt; i++) {
  41 + err = false;
  42 + id = tbl_o.rows[i].id;
  43 + if (id === '') continue;
  44 + id = id.replace(this.row_id_prefix, '');
  45 + arrival_input = $('#'+ this.arrival_input_id_prefix + id);
  46 + arrival = parseInt(arrival_input.val(), 10);
  47 + if (isNaN(arrival) || arrival < 0 || arrival > PROCESS_MAX_START) {
  48 + err = true;
  49 + err_msg['err1'] = 'Incorrect process arrival time (1-' + PROCESS_MAX_LENGTH + ').';
  50 + arrival_input.addClass('input_err');
  51 + } else {
  52 + arrival_input.removeClass('input_err');
  53 + }
  54 + burst_input = $('#'+ this.burst_input_id_prefix + id);
  55 + burst = parseInt(burst_input.val(), 10);
  56 + if (isNaN(burst) || burst < 1 || burst > PROCESS_MAX_LENGTH) {
  57 + err = true;
  58 + err_msg['err2'] = 'Incorrect process burst time (0-' + PROCESS_MAX_START + ').';
  59 + burst_input.addClass('input_err');
  60 + } else {
  61 + burst_input.removeClass('input_err');
  62 + }
  63 + if (err === false) {
  64 + proc.push([arrival, burst]);
  65 + }
  66 + }
  67 +
  68 + var msg = '';
  69 + if (err_msg['err1']) msg += err_msg['err1'];
  70 + if (err_msg['err2']) msg += '\n'+ err_msg['err2'];
  71 + if (msg != '') alert(msg);
  72 + else {
  73 + //console.log(proc);
  74 + proc.sort(mySortingFunc);
  75 + for (var k in proc) {
  76 + process_list.addNew(proc[k][0], proc[k][1]);
  77 + }
  78 + //console.log(proc);
  79 + }
  80 +
  81 +}
  82 +
  83 +function mySortingFunc(el1, el2) {
  84 + return el1[0] - el2[0];
  85 +}
12 lib/application.js
... ... @@ -1,17 +1,25 @@
1 1 var process_list = new ProcessList();
  2 +var process_table = new ProcessTable();
2 3 var time = new Time();
3 4 var gant = new Gant();
4 5
5 6 $(document).ready(function() {
6   - process_list.addNewRow();
  7 + process_table.addRow();
7 8 add_new_process_button_click_handler();
8 9 add_start_button_click_handler();
9 10 and_enter_time_handler();
  11 + add_preview_button_click_handler();
10 12 });
11 13
  14 +function add_preview_button_click_handler() {
  15 + $("#preview").click(function() {
  16 + process_table.proceed();
  17 + });
  18 +}
  19 +
12 20 function add_new_process_button_click_handler() {
13 21 $("#new_process").click(function() {
14   - process_list.addNewRow();
  22 + process_table.addRow();
15 23 });
16 24 }
17 25
1  priority/priority.js
@@ -230,5 +230,6 @@ ProcessList.prototype.start = function() {
230 230 }
231 231 }
232 232 }
  233 +
233 234 gant.animate();
234 235 }
20 stylesheets/application.css
@@ -28,7 +28,7 @@ div.qtime {margin-top: 3px; margin-left: 3px; display:none;}
28 28 #nav a {float: left; margin-right: 10px;}
29 29
30 30 #interruptible {margin-left: 10px;}
31   -#start {width: 80px; font-weight: 700;}
  31 +#start {width: 80px; font-weight: 700; }
32 32
33 33 #ProcessList {
34 34 background: url('images/lines.png');
@@ -51,7 +51,23 @@ div.qtime {margin-top: 3px; margin-left: 3px; display:none;}
51 51 .timeline_item {float: left; position: relative; padding-top: 5px;}
52 52 .timeline_item_text {position: absolute; width: 15px; text-align: center; top: -6px; left: -7px; font-size: 8px;}
53 53 .timeline_item_text span {font-size: 14px;}
54   -
  54 +table#processes {
  55 + border-collapse: collapse;
  56 +}
  57 +table#processes th {
  58 + text-align: center;
  59 +}
  60 +table#processes td, th {
  61 + padding: 0 3px;
  62 +}
  63 +table#processes td input.ptime{
  64 + text-align: right;
  65 + border: 1px solid black;
  66 + width: 80px;
  67 +}
  68 +.input_err {
  69 + background-color: #ff9999;
  70 +}
55 71 table.result_table thead th {
56 72 text-align: left;
57 73 padding: 5px 20px 5px 20px;

0 comments on commit 8ea4961

Please sign in to comment.
Something went wrong with that request. Please try again.