Browse Source

support delete endpoints/counters/rrdfile and refine code

laiwei 8 years ago
parent
commit
cb8d390ca2

+ 106 - 11
rrd/static/js/xperf.js → rrd/static/js/dashboard.js

@@ -8,7 +8,7 @@ function fn_list_endpoints()
     $.getJSON("/api/endpoints", {q: qs, tags: tags, limit:limit, _r:Math.random()}, function(ret){
                 $(".loading").hide();
                 if (!ret.ok) {
-                    alert(ret.msg);
+                    err_message_quietly(ret.msg);
                     return;
                 }
 
@@ -28,7 +28,7 @@ function fn_list_endpoints()
                 fn_check_all_hosts();
     }).error(function(req, ret, errorThrown){
         $(".loading").hide();
-        alert(req.statusText)
+        err_message_quietly(req.statusText)
     })
 }
 
@@ -40,7 +40,7 @@ function fn_list_counters(){
         eids.push(eid);
     });
     if (eids.length === 0){
-        alert("先选定一些endpoints");
+        err_message_quietly("先选定一些endpoints");
         return false;
     }
 
@@ -75,13 +75,108 @@ function fn_list_counters(){
                     tbody_items.find('.shiftCheckbox').shiftcheckbox();
                 }
             }else{
-                alert("搜索失败:" + ret.msg);
+                err_message_quietly("搜索失败:" + ret.msg);
                 return false;
             }
         }
     });
 }
 
+function fn_delete_counters(){
+    var checked_hosts = new Array();
+    $("#tbody-endpoints input:checked").each(function(i, o){
+        if($(o).is(":visible")){
+            var hostfullname = $(o).attr("data-fullname");
+            checked_hosts.push(hostfullname);
+        }
+    });
+    if(checked_hosts.length === 0){
+        err_message_quietly("先选endpoint:)");
+        return false;
+    }
+
+    var checked_items = new Array();
+    $("#tbody-counters input:checked").each(function(i, o){
+        if($(o).is(":visible")){
+            var key_ = $(o).attr("data-fullkey");
+            checked_items.push(key_);
+        }
+    });
+    if (checked_items.length === 0){
+        err_message_quietly("请选择counter");
+        return false;
+    }
+    if(checked_items.length > 10) {
+        err_message_quietly("每次删除不能超过10个,免得你后悔:");
+        return false;
+    }
+
+
+	my_confirm("真的要删除么?这会删除MySQL中对应的内容,也会清除磁盘上对应的数据文件", [ '确定', '取消' ], function() {
+        $.ajax({
+            url: "/api/counters",
+            dataType: "json",
+            method: "DELETE",
+            data: {"endpoints": checked_hosts, "counters": checked_items, "_r": Math.random()},
+            success: function(ret) {
+                if (ret.ok) {
+                    ok_message_quietly(ret.data);
+                }else {
+                    err_message_quietly("请求出错了");
+                }
+            },
+            error: function(){
+                err_message_quietly("请求出错了");
+            }
+        });
+
+	}, function() {
+	});
+
+    return false;
+}
+
+function fn_delete_endpoints(){
+    var checked_hosts = new Array();
+    $("#tbody-endpoints input:checked").each(function(i, o){
+        if($(o).is(":visible")){
+            var hostfullname = $(o).attr("data-fullname");
+            checked_hosts.push(hostfullname);
+        }
+    });
+    if(checked_hosts.length === 0){
+        err_message_quietly("先选endpoint:)");
+        return false;
+    }
+
+    if(checked_hosts.length > 2) {
+        err_message_quietly("每次删除不能超过2个,免得你后悔:");
+        return false;
+    }
+
+	my_confirm("真的要删除么?这会删除MySQL中对应的内容,也会清除磁盘上对应的数据文件", [ '确定', '取消' ], function() {
+        $.ajax({
+            url: "/api/endpoints",
+            dataType: "json",
+            method: "DELETE",
+            data: {"endpoints": checked_hosts, "_r": Math.random()},
+            success: function(ret) {
+                if (ret.ok) {
+                    ok_message_quietly(ret.data);
+                }else {
+                    err_message_quietly("请求出错了");
+                }
+            },
+            error: function(){
+                err_message_quietly("请求出错了");
+            }
+        });
+	}, function() {
+	});
+
+    return false;
+}
+
 
 function filter_endpoint()
 {
@@ -148,7 +243,7 @@ function fn_show_chart(counter)
         }
     });
     if(checked_hosts.length === 0){
-        alert("先选endpoint:)");
+        err_message_quietly("先选endpoint:)");
         return false;
     }
 
@@ -164,11 +259,11 @@ function fn_show_chart(counter)
             if (ret.ok) {
                 setTimeout(function(){w.location='/chart/big?id='+ret.id;}, 0);
             } else {
-                alert("请求出错了");
+                err_message_quietly("请求出错了");
             }
         },
         error: function(){
-            alert("请求出错了");
+            err_message_quietly("请求出错了");
         }
     });
     return false;
@@ -184,7 +279,7 @@ function fn_show_all(graph_type)
         }
     });
     if(checked_hosts.length === 0){
-        alert("先选endpoint:)");
+        err_message_quietly("先选endpoint:)");
         return false;
     }
 
@@ -196,7 +291,7 @@ function fn_show_all(graph_type)
         }
     });
     if (checked_items.length === 0){
-        alert("请选择counter");
+        err_message_quietly("请选择counter");
         return false;
     }
 
@@ -210,11 +305,11 @@ function fn_show_all(graph_type)
             if (ret.ok) {
                 setTimeout(function(){w.location="/charts?id="+ret.id+"&graph_type="+graph_type;}, 0);
             }else {
-                alert("请求出错了");
+                err_message_quietly("请求出错了");
             }
         },
         error: function(){
-            alert("请求出错了");
+            err_message_quietly("请求出错了");
         }
     });
     return false;

+ 39 - 241
rrd/static/js/g.js

@@ -1,250 +1,48 @@
 function err_message_quietly(msg, f) {
-	$.layer({
-		title : false,
-		closeBtn : false,
-		time : 2,
-		dialog : {
-			msg : msg
-		},
-		end : f
-	});
+    $.layer({
+        title: false,
+        closeBtn: false,
+        time: 2,
+        dialog: {
+            msg: msg
+        },
+        end: f
+    });
 }
 
 function ok_message_quietly(msg, f) {
-	$.layer({
-		title : false,
-		closeBtn : false,
-		time : 1,
-		dialog : {
-			msg : msg,
-			type : 1
-		},
-		end : f
-	});
+    $.layer({
+        title: false,
+        closeBtn: false,
+        time: 1,
+        dialog: {
+            msg: msg,
+            type: 1
+        },
+        end: f
+    });
 }
 
 function my_confirm(msg, btns, yes_func, no_func) {
-	$.layer({
-		shade : [ 0 ],
-		area : [ 'auto', 'auto' ],
-		dialog : {
-			msg : msg,
-			btns : 2,
-			type : 4,
-			btn : btns,
-			yes : yes_func,
-			no : no_func
-		}
-	});
-}
-
-// - business function -
-
-function login() {
-	var raw = $('#ldap').prop('checked');
-	if (raw) {
-		useLdap = '1'
-	} else {
-		useLdap = '0'
-	}
-	$.post('/auth/login', {
-		'name' : $('#name').val(),
-		'password' : $("#password").val(),
-        'ldap' : useLdap
-	}, function(json) {
-		if (json.msg.length > 0) {
-			err_message_quietly(json.msg);
-		} else {
-			ok_message_quietly('sign in successfully', function() {
-				var redirect_url = '/user/profile';
-				if (json.data.length > 0) {
-					redirect_url = json.data;
-				}
-				location.href = redirect_url;
-			});
-		}
-	}, "json");
-}
-
-function update_profile() {
-	$.post('/user/profile', {
-		'cnname' : $("#cnname").val(),
-		'email' : $("#email").val(),
-		'phone' : $("#phone").val(),
-		'im' : $("#im").val(),
-		'qq' : $("#qq").val()
-	}, function(json) {
-		if (json.msg.length > 0) {
-			err_message_quietly(json.msg);
-		} else {
-			ok_message_quietly("更新成功:)");
-		}
-	}, "json");
-}
-
-function change_password() {
-	$.post('/user/chpwd', {
-		'old_password' : $("#old_password").val(),
-		'new_password' : $("#new_password").val(),
-		'repeat_password' : $("#repeat_password").val()
-	}, function(json) {
-		if (json.msg.length > 0) {
-			err_message_quietly(json.msg);
-		} else {
-			ok_message_quietly("密码修改成功:)");
-		}
-	}, "json");
-}
-
-function register() {
-	$.post('/auth/register', {
-		'name' : $('#name').val(),
-		'cnname' : $('#cnname').val(),
-		'email' : $('#email').val(),
-		'password' : $("#password").val(),
-		'repeat_password' : $("#repeat_password").val()
-	}, function(json) {
-		if (json.msg.length > 0) {
-			err_message_quietly(json.msg);
-		} else {
-			ok_message_quietly('sign up successfully', function() {
-				location.href = '/auth/login';
-			});
-		}
-	}, "json");
-}
-
-function query_user() {
-	var query = $("#query").val();
-	location.href = "/user/list?query=" + query;
-}
-
-function query_team() {
-	var query = $("#query").val();
-	location.href = "/team/list?query=" + query;
-}
-
-function create_user() {
-	$.post('/user/create', {
-		'name' : $("#name").val(),
-		'cnname' : $("#cnname").val(),
-		'email' : $("#email").val(),
-		'phone' : $("#phone").val(),
-		'im' : $("#im").val(),
-		'qq' : $("#qq").val(),
-		'password' : $("#password").val()
-	}, function(json) {
-		if (json.msg.length > 0) {
-			err_message_quietly(json.msg);
-		} else {
-			ok_message_quietly("create user successfully");
-		}
-	}, "json");
-}
-
-function edit_user(id) {
-	$.post('/admin/user/'+id+'/edit', {
-        'id': id,
-		'cnname' : $("#cnname").val(),
-		'email' : $("#email").val(),
-		'phone' : $("#phone").val(),
-		'im' : $("#im").val(),
-		'qq' : $("#qq").val()
-	}, function(json) {
-		if (json.msg.length > 0) {
-			err_message_quietly(json.msg);
-		} else {
-			ok_message_quietly("更新成功:)");
-		}
-	}, "json");
-}
-
-function reset_password(id) {
-	$.post('/admin/user/'+id+'/chpwd', {
-		'password' : $("#password").val()
-	}, function(json) {
-		if (json.msg.length > 0) {
-			err_message_quietly(json.msg);
-		} else {
-			ok_message_quietly("密码重置成功:)");
-		}
-	}, "json");
-}
-
-function create_team() {
-	$.post('/team/create', {
-		'name' : $("#name").val(),
-		'resume' : $("#resume").val(),
-		'users' : $("#users").val()
-	}, function(json) {
-		if (json.msg.length > 0) {
-			err_message_quietly(json.msg);
-		} else {
-			ok_message_quietly('create team successfully');
-		}
-	}, "json");
-}
-
-function edit_team(tid) {
-	$.post('/team/'+tid+'/edit', {
-		'resume' : $("#resume").val(),
-		'users' : $("#users").val(),
-		'id': tid
-	}, function(json) {
-		if (json.msg.length > 0) {
-			err_message_quietly(json.msg);
-		} else {
-			ok_message_quietly('edit team successfully');
-		}
-	}, "json");
-}
-
-function delete_user(uid) {
-	my_confirm("真的要删除么?通常只有离职的时候才需要删除", [ '确定', '取消' ], function() {
-		$.post('/admin/user/'+uid+'/delete', {
-		}, function(json) {
-			if (json.msg.length > 0) {
-				err_message_quietly(json.msg);
-			} else {
-				ok_message_quietly('delete user successfully', function() {
-					location.reload();
-				});
-			}
-		}, "json");
-	}, function() {
-	});
-}
-
-function delete_team(id) {
-	my_confirm("真的真的要删除么?", [ '确定', '取消' ], function() {
-		$.post('/team/'+id+'/delete', {}, function(json) {
-			if (json.msg.length > 0) {
-				err_message_quietly(json.msg);
-			} else {
-				ok_message_quietly('delete team successfully', function() {
-					location.reload();
-				});
-			}
-		}, "json");
-	}, function() {
-	});
-}
-
-function set_role(uid, obj) {
-	var role = obj.checked ? '1' : '0';
-	$.post('/admin/user/'+uid+'/role', {
-		'role' : role
-	}, function(json) {
-		if (json.msg.length > 0) {
-			err_message_quietly(json.msg);
-			location.reload();
-		} else {
-			if (role == '1') {
-				ok_message_quietly('成功设置为管理员:)');
-			} else if (role == '0') {
-				ok_message_quietly('成功取消管理员权限:)');
-			}
-		}
-	}, "json");
+    $.layer({
+        shade: [ 0 ],
+        area: [ 'auto', 'auto' ],
+        dialog: {
+            msg: msg,
+            btns: 2,
+            type: 4,
+            btn: btns,
+            yes: yes_func,
+            no: no_func
+        }
+    });
+}
+
+function handle_quietly(json, f) {
+    if (json.msg.length > 0) {
+        err_message_quietly(json.msg);
+    } else {
+        ok_message_quietly("successfully:-)", f);
+    }
 }
 

+ 0 - 48
rrd/static/js/portal.js

@@ -1,51 +1,3 @@
-function err_message_quietly(msg, f) {
-    $.layer({
-        title: false,
-        closeBtn: false,
-        time: 2,
-        dialog: {
-            msg: msg
-        },
-        end: f
-    });
-}
-
-function ok_message_quietly(msg, f) {
-    $.layer({
-        title: false,
-        closeBtn: false,
-        time: 1,
-        dialog: {
-            msg: msg,
-            type: 1
-        },
-        end: f
-    });
-}
-
-function my_confirm(msg, btns, yes_func, no_func) {
-    $.layer({
-        shade: [ 0 ],
-        area: [ 'auto', 'auto' ],
-        dialog: {
-            msg: msg,
-            btns: 2,
-            type: 4,
-            btn: btns,
-            yes: yes_func,
-            no: no_func
-        }
-    });
-}
-
-function handle_quietly(json, f) {
-    if (json.msg.length > 0) {
-        err_message_quietly(json.msg);
-    } else {
-        ok_message_quietly("successfully:-)", f);
-    }
-}
-
 // - business function -
 function query_user() {
     var query = $.trim($("#query").val());

+ 250 - 0
rrd/static/js/uic.js

@@ -0,0 +1,250 @@
+function err_message_quietly(msg, f) {
+	$.layer({
+		title : false,
+		closeBtn : false,
+		time : 2,
+		dialog : {
+			msg : msg
+		},
+		end : f
+	});
+}
+
+function ok_message_quietly(msg, f) {
+	$.layer({
+		title : false,
+		closeBtn : false,
+		time : 1,
+		dialog : {
+			msg : msg,
+			type : 1
+		},
+		end : f
+	});
+}
+
+function my_confirm(msg, btns, yes_func, no_func) {
+	$.layer({
+		shade : [ 0 ],
+		area : [ 'auto', 'auto' ],
+		dialog : {
+			msg : msg,
+			btns : 2,
+			type : 4,
+			btn : btns,
+			yes : yes_func,
+			no : no_func
+		}
+	});
+}
+
+// - business function -
+
+function login() {
+	var raw = $('#ldap').prop('checked');
+	if (raw) {
+		useLdap = '1'
+	} else {
+		useLdap = '0'
+	}
+	$.post('/auth/login', {
+		'name' : $('#name').val(),
+		'password' : $("#password").val(),
+        'ldap' : useLdap
+	}, function(json) {
+		if (json.msg.length > 0) {
+			err_message_quietly(json.msg);
+		} else {
+			ok_message_quietly('sign in successfully', function() {
+				var redirect_url = '/user/profile';
+				if (json.data.length > 0) {
+					redirect_url = json.data;
+				}
+				location.href = redirect_url;
+			});
+		}
+	}, "json");
+}
+
+function update_profile() {
+	$.post('/user/profile', {
+		'cnname' : $("#cnname").val(),
+		'email' : $("#email").val(),
+		'phone' : $("#phone").val(),
+		'im' : $("#im").val(),
+		'qq' : $("#qq").val()
+	}, function(json) {
+		if (json.msg.length > 0) {
+			err_message_quietly(json.msg);
+		} else {
+			ok_message_quietly("更新成功:)");
+		}
+	}, "json");
+}
+
+function change_password() {
+	$.post('/user/chpwd', {
+		'old_password' : $("#old_password").val(),
+		'new_password' : $("#new_password").val(),
+		'repeat_password' : $("#repeat_password").val()
+	}, function(json) {
+		if (json.msg.length > 0) {
+			err_message_quietly(json.msg);
+		} else {
+			ok_message_quietly("密码修改成功:)");
+		}
+	}, "json");
+}
+
+function register() {
+	$.post('/auth/register', {
+		'name' : $('#name').val(),
+		'cnname' : $('#cnname').val(),
+		'email' : $('#email').val(),
+		'password' : $("#password").val(),
+		'repeat_password' : $("#repeat_password").val()
+	}, function(json) {
+		if (json.msg.length > 0) {
+			err_message_quietly(json.msg);
+		} else {
+			ok_message_quietly('sign up successfully', function() {
+				location.href = '/auth/login';
+			});
+		}
+	}, "json");
+}
+
+function query_user() {
+	var query = $("#query").val();
+	location.href = "/user/list?query=" + query;
+}
+
+function query_team() {
+	var query = $("#query").val();
+	location.href = "/team/list?query=" + query;
+}
+
+function create_user() {
+	$.post('/user/create', {
+		'name' : $("#name").val(),
+		'cnname' : $("#cnname").val(),
+		'email' : $("#email").val(),
+		'phone' : $("#phone").val(),
+		'im' : $("#im").val(),
+		'qq' : $("#qq").val(),
+		'password' : $("#password").val()
+	}, function(json) {
+		if (json.msg.length > 0) {
+			err_message_quietly(json.msg);
+		} else {
+			ok_message_quietly("create user successfully");
+		}
+	}, "json");
+}
+
+function edit_user(id) {
+	$.post('/admin/user/'+id+'/edit', {
+        'id': id,
+		'cnname' : $("#cnname").val(),
+		'email' : $("#email").val(),
+		'phone' : $("#phone").val(),
+		'im' : $("#im").val(),
+		'qq' : $("#qq").val()
+	}, function(json) {
+		if (json.msg.length > 0) {
+			err_message_quietly(json.msg);
+		} else {
+			ok_message_quietly("更新成功:)");
+		}
+	}, "json");
+}
+
+function reset_password(id) {
+	$.post('/admin/user/'+id+'/chpwd', {
+		'password' : $("#password").val()
+	}, function(json) {
+		if (json.msg.length > 0) {
+			err_message_quietly(json.msg);
+		} else {
+			ok_message_quietly("密码重置成功:)");
+		}
+	}, "json");
+}
+
+function create_team() {
+	$.post('/team/create', {
+		'name' : $("#name").val(),
+		'resume' : $("#resume").val(),
+		'users' : $("#users").val()
+	}, function(json) {
+		if (json.msg.length > 0) {
+			err_message_quietly(json.msg);
+		} else {
+			ok_message_quietly('create team successfully');
+		}
+	}, "json");
+}
+
+function edit_team(tid) {
+	$.post('/team/'+tid+'/edit', {
+		'resume' : $("#resume").val(),
+		'users' : $("#users").val(),
+		'id': tid
+	}, function(json) {
+		if (json.msg.length > 0) {
+			err_message_quietly(json.msg);
+		} else {
+			ok_message_quietly('edit team successfully');
+		}
+	}, "json");
+}
+
+function delete_user(uid) {
+	my_confirm("真的要删除么?通常只有离职的时候才需要删除", [ '确定', '取消' ], function() {
+		$.post('/admin/user/'+uid+'/delete', {
+		}, function(json) {
+			if (json.msg.length > 0) {
+				err_message_quietly(json.msg);
+			} else {
+				ok_message_quietly('delete user successfully', function() {
+					location.reload();
+				});
+			}
+		}, "json");
+	}, function() {
+	});
+}
+
+function delete_team(id) {
+	my_confirm("真的真的要删除么?", [ '确定', '取消' ], function() {
+		$.post('/team/'+id+'/delete', {}, function(json) {
+			if (json.msg.length > 0) {
+				err_message_quietly(json.msg);
+			} else {
+				ok_message_quietly('delete team successfully', function() {
+					location.reload();
+				});
+			}
+		}, "json");
+	}, function() {
+	});
+}
+
+function set_role(uid, obj) {
+	var role = obj.checked ? '1' : '0';
+	$.post('/admin/user/'+uid+'/role', {
+		'role' : role
+	}, function(json) {
+		if (json.msg.length > 0) {
+			err_message_quietly(json.msg);
+			location.reload();
+		} else {
+			if (role == '1') {
+				ok_message_quietly('成功设置为管理员:)');
+			} else if (role == '0') {
+				ok_message_quietly('成功取消管理员权限:)');
+			}
+		}
+	}, "json");
+}
+

+ 1 - 1
rrd/templates/auth/base.html

@@ -2,7 +2,7 @@
 
 {%block head_js%}
     {{super()}}
-    <script src="{{url_for('static', filename='js/g.js')}}"></script>
+    <script src="{{url_for('static', filename='js/uic.js')}}"></script>
 {%endblock%}
 
 {%block navbar%}

+ 1 - 0
rrd/templates/base.html

@@ -33,6 +33,7 @@
     {% block head_js %}
         <script src="{{url_for('static', filename='js/jquery.min.js')}}"></script>
         <script src="{{url_for('static', filename='layer/layer.min.js')}}"></script>
+        <script src="{{url_for('static', filename='js/g.js')}}"></script>
         <script type="text/javascript" src="{{ url_for('static', filename='layer/extend/layer.ext.js') }}"></script>
         <script src="{{url_for('static', filename='js/jquery.query.js')}}"></script>
         <script src="{{url_for('static', filename='bootstrap3/js/bootstrap.min.js')}}"></script>

+ 18 - 4
rrd/templates/index.html

@@ -7,7 +7,7 @@
 {{super()}}
 
 <script src="/static/js/jquery.shiftcheckbox.js" type= "text/javascript" ></script>
-<script src="/static/js/xperf.js?_v=0.1.0"></script>
+<script src="/static/js/dashboard.js?_v=0.1.0"></script>
 <script>
 
         $(function(){
@@ -101,10 +101,23 @@
                         </div>
 
                         <table class="table table-striped">
-                            <thead> <tr> <p class="help-block"><span class="text-warning">支持shift多选</span></p>
-                                <th width="30px" colspan=2><input type="checkbox" id="check_all_endpoints"></th>
-                                <th><button class="btn btn-link btn-xs pull-right" onclick="fn_list_counters();return false;">刷新counter列表</button></th>
+                            <thead> <tr> 
+                                <th>
+                                <span style="display: inline-block;vertical-align:middle;">
+                                    <input type="checkbox" id="check_all_endpoints" style="height:13px;">
+                                    <span class="text-warning">支持shift分段选择</span>
+                                </span>
+                                <span class="pull-right">
+                                    <button class="btn btn-default btn-xs" onclick="fn_list_counters();return false;">刷新counter列表</button>
+                                    <button class="btn btn-default btn-xs" onclick="fn_delete_endpoints();return false;">删除endpoints</button>
+                                </span>
+                                </th>
                             </tr></thead>
+                        </table>
+                        <table class="table table-striped">
+                            <thead>
+                                <th width="15"></th> <th></th>
+                            </thead>
                             <tbody id="tbody-endpoints"> </tbody>
                         </table>
 
@@ -150,6 +163,7 @@
                                 </div>
 
                                 <div class="dropdown form-group pull-right">
+                                    <button class="btn btn-default btn-sm" onclick="fn_delete_counters();return false;">删除counters</button>
                                     <a class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" href="#"> 看图 <span class="caret"></span></a>
                                     <ul class="dropdown-menu" role="menu">
                                       <li><a href="#" class="btn btn-link btn-xs" onclick="fn_show_all('h');return false;">Endpoint视角</a></li>

+ 1 - 0
rrd/templates/portal/blank.html

@@ -20,6 +20,7 @@
     <script type="text/javascript" src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
     <script type="text/javascript" src="{{ url_for('static', filename='js/bootstrap.js') }}"></script>
     <script type="text/javascript" src="{{ url_for('static', filename='layer/layer.min.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/g.js') }}"></script>
     <script type="text/javascript" src="{{ url_for('static', filename='layer/extend/layer.ext.js') }}"></script>
     <script type="text/javascript" src="{{ url_for('static', filename='js/moment-with-locales.js') }}"></script>
     <script type="text/javascript" src="{{ url_for('static', filename='js/portal.js') }}"></script>

+ 1 - 1
rrd/templates/team/base.html

@@ -2,7 +2,7 @@
 
 {%block head_js%}
     {{super()}}
-    <script src="{{url_for('static', filename='js/g.js')}}"></script>
+    <script src="{{url_for('static', filename='js/uic.js')}}"></script>
 {%endblock%}
 
 {%block navbar%}

+ 1 - 1
rrd/templates/user/base.html

@@ -2,7 +2,7 @@
 
 {%block head_js%}
     {{super()}}
-    <script src="{{url_for('static', filename='js/g.js')}}"></script>
+    <script src="{{url_for('static', filename='js/uic.js')}}"></script>
 {%endblock%}
 
 {%block navbar%}

+ 55 - 1
rrd/view/api.py

@@ -18,6 +18,8 @@ def api_endpoints():
     tags = ','.join(re.split('\s*,\s*', raw_tag))
     limit = int(request.args.get("limit") or 100)
 
+    if not q:
+        q = "."
     if not q and not tags:
         ret["msg"] = "no query params given"
         return json.dumps(ret)
@@ -35,7 +37,6 @@ def api_endpoints():
 
     return json.dumps(ret)
 
-#done
 @app.route("/api/counters", methods=["POST"])
 def api_get_counters():
     ret = {
@@ -70,3 +71,56 @@ def api_get_counters():
     ret['ok'] = True
 
     return json.dumps(ret)
+
+
+@app.route("/api/counters", methods=["DELETE"])
+def api_delete_counters():
+    ret = {
+            "ok": False,
+            "msg": "",
+    }
+
+    endpoints = request.form.getlist("endpoints[]") or []
+    counters = request.form.getlist("counters[]") or []
+    if len(endpoints) == 0 or len(counters) == 0:
+        ret['msg'] = "no endpoint and counter"
+        return json.dumps(ret)
+
+    h = {"Content-type": "application/json"}
+    d = {
+            "endpoints": endpoints,
+            "counters": counters,
+    }
+    r = corelib.auth_requests("DELETE", config.API_ADDR + "/graph/counter", headers=h, data=json.dumps(d))
+    if r.status_code != 200:
+        abort(r.status_code, r.text)
+    j = r.json()
+
+    ret["ok"] = True
+    ret["data"] = "%s counters affected" %j.get("affected_counter")
+    return json.dumps(ret)
+
+
+@app.route("/api/endpoints", methods=["DELETE"])
+def api_delete_endpoints():
+    ret = {
+            "ok": False,
+            "msg": "",
+    }
+
+    endpoints = request.form.getlist("endpoints[]") or []
+    if len(endpoints) == 0:
+        ret['msg'] = "no endpoint"
+        return json.dumps(ret)
+
+    h = {"Content-type": "application/json"}
+    d = endpoints
+
+    r = corelib.auth_requests("DELETE", config.API_ADDR + "/graph/endpoint", headers=h, data=json.dumps(d))
+    if r.status_code != 200:
+        abort(r.status_code, r.text)
+    j = r.json()
+
+    ret["ok"] = True
+    ret["data"] = "%s counters affected, %s endpoints affected" %(j.get("affected_counter"), j.get("affected_endpoint"))
+    return json.dumps(ret)