Skip to content

Commit

Permalink
Merge pull request #29 from onur/filter
Browse files Browse the repository at this point in the history
Add filtering input for processes
  • Loading branch information
GuillaumeGomez committed Sep 11, 2018
2 parents b260156 + e34b563 commit acaf0fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
.progress-bar-ours {
background-color: #69D2E7;
}
.i-filter {
padding: 4px;
border-radius: 3px;
border: 1px solid #ccc;
width: 100%;
outline-color: #51afd0;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -215,6 +222,7 @@ <h2>{{ sysinfo.hostname }} &mdash; {{ sysinfo.uptime }}</h2>
<div class="col-xs-12">
<div class="panel panel-default">
<div class="panel-body">
<input placeholder="Filter by Name, PID, UID or GID" v-model="procFilter" class="i-filter">
<table class="table table-striped table-hover">
<thead>
<tr>
Expand Down Expand Up @@ -306,6 +314,7 @@ <h2>{{ sysinfo.hostname }} &mdash; {{ sysinfo.uptime }}</h2>
'#E0E4CC', '#F9CDAD', '#C02942', '#F38630', '#C8C8A9', '#542437',
'#FA6900', '#83AF9B', '#A7DBD8',
],
procFilter: '',
},
created: function() {
this.fetchData();
Expand Down Expand Up @@ -502,7 +511,7 @@ <h2>{{ sysinfo.hostname }} &mdash; {{ sysinfo.uptime }}</h2>
};
},
sortBy: function(sortKey) {
this.reverse = (this.sortKey == this.columns[sortKey]) ? ! this.reverse : true;
this.reverse = (this.sortKey == this.columns[sortKey]) ? !this.reverse : true;
this.sortKey = this.columns[sortKey];
},
},
Expand All @@ -512,8 +521,15 @@ <h2>{{ sysinfo.hostname }} &mdash; {{ sysinfo.uptime }}</h2>
return [];
}
var self = this;
var filter = self.procFilter.trim().toLowerCase();
var order = self.reverse ? -1 : 1;
return this.sysinfo.process_list.sort(function(a, b) {
return this.sysinfo.process_list.filter(function(a) {
return filter.length === 0 ||
(a['pid'] + '').indexOf(filter) !== -1 ||
a['name'].toLowerCase().indexOf(filter) !== -1 ||
(a['uid'] + '').indexOf(filter) !== -1 ||
(a['gid'] + '').indexOf(filter) !== -1;
}).sort(function(a, b) {
a = a[self.sortKey];
b = b[self.sortKey];
return (a === b ? 0 : a > b ? 1 : -1) * order;
Expand Down
6 changes: 5 additions & 1 deletion src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,9 @@ pub fn start_web_server(sock_addr: Option<String>) -> HttpResult<Listening> {
});
let mut iron = Iron::new(SysinfoIronHandler(data_handler));
iron.threads = 4;
iron.http(sock_addr.unwrap_or("localhost:3000".to_owned()))
let ret = iron.http(sock_addr.unwrap_or("localhost:3000".to_owned()));
if ret.is_ok() {
println!("Started server on port 3000");
}
ret
}

0 comments on commit acaf0fd

Please sign in to comment.