Permalink
Browse files

Table for FCFS

  • Loading branch information...
ivovdry committed Apr 3, 2011
1 parent 697210c commit 8ea49617c0c19c9ce98ec850825daa88c8f7235e
@@ -5,6 +5,7 @@
<script src="../lib/vendor/jquery-1.5.min.js" type="text/javascript"></script>
<script src="../lib/vendor/jquery.tablesorter.min.js" type="text/javascript"></script>
<script src="../lib/Process.js" type="text/javascript"></script>
+ <script src="../lib/ProcessTable.js" type="text/javascript"></script>
<script src="../lib/ProcessList.js" type="text/javascript"></script>
<script src="../lib/Gant.js" type="text/javascript"></script>
<script src="../lib/Time.js" type="text/javascript"></script>
@@ -25,17 +26,18 @@ <h1>
<a href="../priority/priority.html">Priority</a>
</div>
<div class="clear">
- <table id="processes" border="1">
+ <b>Processes: <input id="new_process" type="button" value="New"></b>
+ <table id="processes" border="0">
<thead>
<tr>
- <th>#</th>
<th>Arrival time</th>
<th>Burst time</th>
- <th>Action</th>
+ <th></th>
</tr>
</thead>
</table>
- <input id="new_process" type="button" value="New Process"><input id="start" type="button" value="Start">
+ <input id="preview" type="button" value="Preview">
+ <input id="start" type="button" value="Start">
<div class="clear"></div>
<h2 class="main">
Processes:
View
@@ -4,6 +4,7 @@ var PX_PER_SECOND = 21;
var DELAY = 100;
function Process(i, arrival, burst, priority, color) {
+ /*
this.id = -1;
if (arrival < 0 || arrival > PROCESS_MAX_START) {
@@ -15,7 +16,7 @@ function Process(i, arrival, burst, priority, color) {
alert('Incorrect process burst time (0-' + PROCESS_MAX_START + ').');
return false;
}
-
+*/
this.id = i;
this.burst = burst;
this.remaining_burst = burst;
View
@@ -10,61 +10,32 @@ function ProcessList() {
this.max_arrival = 0;
}
-ProcessList.prototype.deleteRow = function(row_id) {
- var row_o = $('#'+ row_id)[0];
- row_o.parentNode.removeChild(row_o);
- this.refreshTable();
-}
-
-ProcessList.prototype.refreshTable = function() {
- var table_o = $('#processes')[0];
- var row_cnt = table_o.rows.length;
-
- for (var i = 0; i < row_cnt; i++) {
- console.log(table_o.rows[i].id);
- }
-}
-
-ProcessList.prototype.addNewRow = function() {
- var new_id = this.count + 1;
- var dbtn_id = 'dbtn_'+ new_id;
- var row_id = 'process_row_'+ new_id;
- var row_html = '<tr id="'+ row_id +'">';
- row_html += '<td id="pnr_'+ new_id +'">P'+ new_id +'</td>';
- row_html += '<td><input type="text" id="atime_'+ new_id +'" maxlength="5" size="5" value=""></td>';
- row_html += '<td><input type="text" id="btime_'+ new_id +'" maxlength="5" size="5" value=""></td>';
- row_html += '<td><input type="button" id="'+ dbtn_id +'" value="Delete"></td>';
- row_html += '</tr>';
- $('#processes').append(row_html);
- $('#'+ dbtn_id).click(function() {
- ProcessList.prototype.deleteRow(row_id);
- });
- this.count++;
- return;
+ProcessList.prototype.addNew = function(arrival, burst, priority) {
+/*
var arrival = parseInt(arrival, 10);
burst = parseInt(burst, 10);
if (isNaN(arrival) || isNaN(burst)) {
alert('Incorrect numbers.');
return false;
- }
-
+ }*/
+ /*
if (this.max_arrival > arrival) {
alert('Incorrect arrival time. Arrival must be >= ' + this.max_arrival);
return false;
}
-
+ */
$("h2.main").show();
-
+ var new_id = this.count + 1;
var new_color;
if (priority != undefined) {
new_color = this.colors_priority[priority - 1][new_id % this.colors_priority[priority - 1].length];
} else {
new_color = this.colors[new_id % this.colors.length];
}
var p = new Process(new_id, arrival, burst, priority, new_color);
- if (p.id == -1) return false;
+ //if (p.id == -1) return false;
this.max_arrival = arrival;
$('#ProcessList').append(p.output());
View
@@ -0,0 +1,85 @@
+function ProcessTable() {
+ this.count = 0;
+ this.row_id_prefix = 'process_row_';
+ this.arrival_input_id_prefix = 'atime_';
+ this.burst_input_id_prefix = 'btime_';
+}
+
+ProcessTable.prototype.addRow = function() {
+ var new_id = this.count + 1;
+ var dbtn_id = 'dbtn_'+ new_id;
+ var row_id = this.row_id_prefix + new_id;
+ var row_html = '<tr id="'+ row_id +'">';
+ row_html += '<td><input type="text" class="ptime" id="'+ this.arrival_input_id_prefix + new_id +'" maxlength="5" value=""></td>';
+ row_html += '<td><input type="text" class="ptime" id="'+ this.burst_input_id_prefix + new_id +'" maxlength="5" value=""></td>';
+ row_html += '<td><input type="button" id="'+ dbtn_id +'" value="Delete"></td>';
+ row_html += '</tr>';
+ $('#processes').append(row_html);
+ $('#'+ dbtn_id).click(function() {
+ process_table.deleteRow(row_id);
+ });
+ this.count++;
+}
+
+ProcessTable.prototype.deleteRow = function(row_id) {
+ var row_o = $('#'+ row_id)[0];
+ row_o.parentNode.removeChild(row_o);
+}
+
+ProcessTable.prototype.proceed = function() {
+ var proc = [];
+ var tbl_o = $('#processes')[0];
+ var rows_cnt = tbl_o.rows.length;
+ var id;
+ var arrival;
+ var arrival_input;
+ var burst;
+ var burst_input;
+ var err;
+ var err_msg = {};
+ for (var i = 0; i < rows_cnt; i++) {
+ err = false;
+ id = tbl_o.rows[i].id;
+ if (id === '') continue;
+ id = id.replace(this.row_id_prefix, '');
+ arrival_input = $('#'+ this.arrival_input_id_prefix + id);
+ arrival = parseInt(arrival_input.val(), 10);
+ if (isNaN(arrival) || arrival < 0 || arrival > PROCESS_MAX_START) {
+ err = true;
+ err_msg['err1'] = 'Incorrect process arrival time (1-' + PROCESS_MAX_LENGTH + ').';
+ arrival_input.addClass('input_err');
+ } else {
+ arrival_input.removeClass('input_err');
+ }
+ burst_input = $('#'+ this.burst_input_id_prefix + id);
+ burst = parseInt(burst_input.val(), 10);
+ if (isNaN(burst) || burst < 1 || burst > PROCESS_MAX_LENGTH) {
+ err = true;
+ err_msg['err2'] = 'Incorrect process burst time (0-' + PROCESS_MAX_START + ').';
+ burst_input.addClass('input_err');
+ } else {
+ burst_input.removeClass('input_err');
+ }
+ if (err === false) {
+ proc.push([arrival, burst]);
+ }
+ }
+
+ var msg = '';
+ if (err_msg['err1']) msg += err_msg['err1'];
+ if (err_msg['err2']) msg += '\n'+ err_msg['err2'];
+ if (msg != '') alert(msg);
+ else {
+ //console.log(proc);
+ proc.sort(mySortingFunc);
+ for (var k in proc) {
+ process_list.addNew(proc[k][0], proc[k][1]);
+ }
+ //console.log(proc);
+ }
+
+}
+
+function mySortingFunc(el1, el2) {
+ return el1[0] - el2[0];
+}
View
@@ -1,17 +1,25 @@
var process_list = new ProcessList();
+var process_table = new ProcessTable();
var time = new Time();
var gant = new Gant();
$(document).ready(function() {
- process_list.addNewRow();
+ process_table.addRow();
add_new_process_button_click_handler();
add_start_button_click_handler();
and_enter_time_handler();
+ add_preview_button_click_handler();
});
+function add_preview_button_click_handler() {
+ $("#preview").click(function() {
+ process_table.proceed();
+ });
+}
+
function add_new_process_button_click_handler() {
$("#new_process").click(function() {
- process_list.addNewRow();
+ process_table.addRow();
});
}
View
@@ -230,5 +230,6 @@ ProcessList.prototype.start = function() {
}
}
}
+
gant.animate();
}
@@ -28,7 +28,7 @@ div.qtime {margin-top: 3px; margin-left: 3px; display:none;}
#nav a {float: left; margin-right: 10px;}
#interruptible {margin-left: 10px;}
-#start {width: 80px; font-weight: 700;}
+#start {width: 80px; font-weight: 700; }
#ProcessList {
background: url('images/lines.png');
@@ -51,7 +51,23 @@ div.qtime {margin-top: 3px; margin-left: 3px; display:none;}
.timeline_item {float: left; position: relative; padding-top: 5px;}
.timeline_item_text {position: absolute; width: 15px; text-align: center; top: -6px; left: -7px; font-size: 8px;}
.timeline_item_text span {font-size: 14px;}
-
+table#processes {
+ border-collapse: collapse;
+}
+table#processes th {
+ text-align: center;
+}
+table#processes td, th {
+ padding: 0 3px;
+}
+table#processes td input.ptime{
+ text-align: right;
+ border: 1px solid black;
+ width: 80px;
+}
+.input_err {
+ background-color: #ff9999;
+}
table.result_table thead th {
text-align: left;
padding: 5px 20px 5px 20px;

0 comments on commit 8ea4961

Please sign in to comment.