OSDN Git Service

Add watch window (#3)
authorkeisuke fukawa <keisuke@karesansui-project.info>
Fri, 9 Apr 2010 03:26:21 +0000 (12:26 +0900)
committerkeisuke fukawa <keisuke@karesansui-project.info>
Fri, 9 Apr 2010 03:26:21 +0000 (12:26 +0900)
karesansui/db/access/watch.py
karesansui/gadget/watch.py
karesansui/lib/const.py
karesansui/templates/default/watch/watch.part

index 326f03d..7446c0b 100644 (file)
@@ -14,6 +14,7 @@
 from karesansui.db.model.watch import Watch
 from karesansui.db.model.machine import Machine
 from karesansui.db.access import dbsave, dbupdate, dbdelete
+from karesansui.db.access.search import findbyand as _findbyand
 
 # -- all
 def findbyall(session, is_deleted=False):
@@ -40,6 +41,9 @@ def findby1name(session, name, is_deleted=False):
         Watch.name == name).filter(
         Watch.is_deleted == is_deleted).first()
 
+def findbyand(session, query):
+    return _findbyand(session, query, Watch, [Watch.name])
+
 @dbupdate
 def logical_delete(session, watch):
     watch.is_deleted = True
index 88da661..a58c34f 100644 (file)
@@ -21,15 +21,19 @@ from karesansui.lib.checker import Checker, \
     CHECK_LENGTH, CHECK_MIN, CHECK_MAX
 
 from karesansui.db.access.watch import \
-    findbyall, findby1, new as w_new, save as w_save
+    findbyall, findby1, findbyand, \
+    new as w_new, save as w_save
 
 from karesansui.lib.utils import is_param, create_plugin_selector
 
-from karesansui.lib.const import COLLECTD_PLUGIN_CPU, COLLECTD_PLUGIN_DF, \
+from karesansui.lib.const import WATCH_LIST_RANGE, \
+    COLLECTD_PLUGIN_CPU, COLLECTD_PLUGIN_DF, \
     COLLECTD_PLUGIN_DISK, COLLECTD_PLUGIN_INTERFACE, COLLECTD_PLUGIN_LIBVIRT, \
     COLLECTD_PLUGIN_MEMORY, COLLECTD_PLUGIN_UPTIME, COLLECTD_CPU_TYPE_INSTANCE, \
     COLLECTD_MEMORY_TYPE_INSTANCE, COLLECTD_DF_DS, COLLECTD_DISK_TYPE, \
-    COLLECTD_DISK_DS, COLLECTD_INTERFACE_TYPE, COLLECTD_INTERFACE_DS
+    COLLECTD_DISK_DS, COLLECTD_INTERFACE_TYPE, COLLECTD_INTERFACE_DS, \
+    COLLECTD_CPU_TYPE, COLLECTD_MEMORY_TYPE, COLLECTD_DF_TYPE, \
+    COLLECTD_UPTIME_TYPE, COLLECTD_LIBVIRT_TYPE
 
 def validates_watch(obj):
     check = True
@@ -62,9 +66,48 @@ class Watch(Rest):
 
             return True
 
-        # get watch list
-        watch_list = findbyall(self.orm)
-        self.view.watch_list = watch_list
+
+
+        if not validates_query(self):
+            self.logger.debug("Show watch is failed, "
+                              "Invalid query value "
+                              "- query=%s" % self.input.q)
+            return web.badrequest(self.view.alert)
+
+        if not validates_page(self):
+            self.logger.debug("Show watch is failed, "
+                              "Invalid page value - page=%s" % self.input.p)
+            return web.badrequest(self.view.alert)
+
+        if is_param(self.input, 'q') is True:
+            watchs = findbyand(self.orm, self.input.q)
+            if not watchs:
+                self.logger.debug("Show watch is failed, "
+                                  "Could not find watch "
+                                  "- query=%s" % self.input.q)
+                return web.nocontent()
+            self.view.search_value = self.input.q
+        else:
+            watchs = findbyall(self.orm)
+            self.view.search_value = ""
+            if not watchs:
+                self.logger.debug("Show watch is failed, "
+                                  "Did not exist watch list")
+                return web.notfound()
+
+        if is_param(self.input, 'p') is True:
+            start = int(self.input.p)
+        else:
+            start = 0
+
+        pager = Pager(watchs, start, WATCH_LIST_RANGE)
+        if not pager.exist_now_page():
+            self.logger.debug("Show watch is failed, "
+                              "Could not find page - page=%s" % self.input.p)
+            return web.nocontent()
+
+        self.view.pager = pager
+        self.view.input = self.input
 
         return True
 
@@ -82,33 +125,40 @@ class Watch(Rest):
 
         if plugin == COLLECTD_PLUGIN_CPU:
             #cpu method
-            # get param
             type_instance = self.input.cpu_status
-            type = "cpu"
+            type = COLLECTD_CPU_TYPE
 
         elif plugin == COLLECTD_PLUGIN_MEMORY:
             #memory method
-            b=1
+            type_instance = self.input.memory_status
+            type = COLLECTD_MEMORY_TYPE
 
         elif plugin == COLLECTD_PLUGIN_DF:
             #df method
-            c=1
+            type = COLLECTD_DF_TYPE
 
         elif plugin == COLLECTD_PLUGIN_DISK:
             #disk method
-            d=1
+            type = self.input.disk_disk_status
 
         elif plugin == COLLECTD_PLUGIN_INTERFACE:
             #interface method
-            e=1
+            type = self.input.network_status
 
         elif plugin == COLLECTD_PLUGIN_LIBVIRT:
             #libvirt method
-            f=1
+            if self.input.libvirt_target == "cpu":
+                type = COLLECTD_LIBVIRT_TYPE['CPU_TOTAL']
+
+            elif self.input.libvirt_target == "disk":
+                type = "disk_" + self.input.libvirt_disk_status
+
+            elif self.input.libvirt_target == "network":
+                type = "if_" + self.input.libvirt_network_status
 
         elif plugin == COLLECTD_PLUGIN_UPTIME:
             #uptime method
-            g=1
+            type = COLLECTD_UPTIME_TYPE
 
 
         plugin_selector = create_plugin_selector(plugin_instance, type, type_instance)
index 0d94248..38bdbf6 100644 (file)
@@ -61,6 +61,7 @@ DEFAULT_LIST_RANGE = 10
 JOB_LIST_RANGE = DEFAULT_LIST_RANGE
 USER_LIST_RANGE = DEFAULT_LIST_RANGE
 TAG_LIST_RANGE = DEFAULT_LIST_RANGE
+WATCH_LIST_RANGE = DEFAULT_LIST_RANGE
 
 # use for virt library
 VIRT_LIBVIRT_DATA_DIR    = VENDOR_DATA_DIR + "/libvirt"
index d90ee4a..de5950a 100644 (file)
@@ -27,47 +27,47 @@ $(document).ready(function(){
     });
 
 
-$("#watch_list tbody tr").each(function(){
-    $(this).one("click.once", function(){
-        // edit
-        $("#edit_watch").one("click", function(){
-            var uri = "${ctx.homepath}${ctx.path}".replace(".part", "");
-            var target_id = selected_row("watch_list_row");
-
-            if(target_id == undefined){
-                alert_on(".alert", "ERROR", "${_('Please select a target.')}");
-                tool_reset("#edit_watch");
-            } else {
-                var url = uri + "/" + target_id + ".part?mode=input";
-                grayout_view("GET",
-                    url,
-                    "${_('Watch Settings')}",
-                    "${ctx.homepath}${ctx.path}");
-            }
-        });
-        tool_reset("#edit_watch");
-
-        // delete
-        $("#delete_watch").click(function(){
-            var uri = "${ctx.homepath}${ctx.path}".replace(".part", "");
-            var target_id = selected_row("watch_list_row");
-
-            if(target_id == undefined){
-                alert_on(".alert", "ERROR", "${_('Please select a target.')}");
-                tool_reset("#delete_watch");
-            } else {
-                var url = uri + "/" + target_id + ".part";
-                var param = null;
-                delete_dialog("#dialog", url, param, "${ctx.homepath}${ctx.path}", "#delete_watch");
-            }
-        });
-        tool_reset("#delete_watch");
+    $("#watch_list tbody tr").each(function(){
+        $(this).one("click.once", function(){
+            // edit
+            $("#edit_watch").one("click", function(){
+                var uri = "${ctx.homepath}${ctx.path}".replace(".part", "");
+                var target_id = selected_row("watch_list_row");
+
+                if(target_id == undefined){
+                    alert_on(".alert", "ERROR", "${_('Please select a target.')}");
+                    tool_reset("#edit_watch");
+                } else {
+                    var url = uri + "/" + target_id + ".part?mode=input";
+                    grayout_view("GET",
+                        url,
+                        "${_('Watch Settings')}",
+                        "${ctx.homepath}${ctx.path}");
+                }
+            });
+            tool_reset("#edit_watch");
+
+            // delete
+            $("#delete_watch").click(function(){
+                var uri = "${ctx.homepath}${ctx.path}".replace(".part", "");
+                var target_id = selected_row("watch_list_row");
+
+                if(target_id == undefined){
+                    alert_on(".alert", "ERROR", "${_('Please select a target.')}");
+                    tool_reset("#delete_watch");
+                } else {
+                    var url = uri + "/" + target_id + ".part";
+                    var param = null;
+                    delete_dialog("#dialog", url, param, "${ctx.homepath}${ctx.path}", "#delete_watch");
+                }
+            });
+            tool_reset("#delete_watch");
 
-        $("#watch_list tbody tr").each(function(){
-            $(this).unbind("click.once");
+            $("#watch_list tbody tr").each(function(){
+                $(this).unbind("click.once");
+            });
         });
     });
-});
 
     // add
     $("#add_watch").click(function(){
@@ -77,6 +77,37 @@ $("#watch_list tbody tr").each(function(){
         "${ctx.homepath}${ctx.path}");
     });
 
+    // pager
+    $("a[id*='watch_page']").click(function(){
+        var page = $(this).attr("id").replace("watch_page", "");
+        var search = $("#search_value").serialize().replace("q=", "");
+        var query = "?p=" + page;
+        if(search != ""){
+            query = query + "&q=" + search;
+        }
+        ajax_get(
+            "#watch_display",
+            "${ctx.homepath}${ctx.path}" + query,
+            null
+        );
+    });
+
+    // search
+    $("#search_button").click(function(){
+        var search = $("#search_value").serialize().replace("q=", "");
+        var query = "";
+        if(search != ""){
+            query = query + "?q=" + search;
+        }
+        ajax_get(
+            "#watch_display",
+            "${ctx.homepath}${ctx.path}" + query,
+            null
+        );
+    });
+
+
+
     // init
     $("#action>a").hover(
         function(){tool_over(this);},
@@ -150,6 +181,39 @@ $("#watch_list tbody tr").each(function(){
 
                             <div id="list-box">
                                 <div id="minner">
+                                    <div id="watch-search" style="text-align: right;">
+                                        <input type="text" id="search_value" name="q" value="${search_value}" maxlength="256">&nbsp;&nbsp;
+                                        <a href="#" name="search_button" id="search_button" class="button">
+                                            <span class="button-left">&nbsp;</span><span class="button-right">${_('Search')}</span><br/><br/>
+                                        </a>
+                                    </div>
+
+                                    <div class="pager">
+% if pager.exist_prev_page():
+                                        &nbsp;&nbsp;<a href="#"  name="p" id="watch_page${pager.get_prev_page()}"><img name="pager_button" class="prev" src="${ctx.homepath}/static/images/list-pre.gif" alt="prev" /></a>
+% else:
+                                        &nbsp;&nbsp;<img name="pager_button" class="prev" src="${ctx.homepath}/static/images/list-pre-invalid.gif" alt="prev" />
+% endif
+% if pager.get_page_list() == []:
+                                        &nbsp;&nbsp;<span class="active">0</span>
+% else:
+    % for x in pager.get_page_list():
+        % if pager.is_now_page(x):
+                                        &nbsp;&nbsp;<span class="active">${x}</span>
+        % else:
+                                        &nbsp;&nbsp;<a href="#" class="link" name="p" id="watch_page${x}">${x}</a>
+        % endif
+    % endfor
+% endif
+% if pager.exist_next_page():
+                                        &nbsp;&nbsp;<a href="#"  name="p" id="watch_page${pager.get_next_page()}"><img name="pager_button" class="next" src="${ctx.homepath}/static/images/list-next.gif" alt="next" /></a>
+% else:
+                                        &nbsp;&nbsp;<img name="pager_button" class="next" src="${ctx.homepath}/static/images/list-next-invalid.gif" alt="next" />
+% endif
+                                        <span class="search-result">[${pager.get_start()}&nbsp;-&nbsp;${pager.get_end()}]&nbsp;of&nbsp;${pager.get_total()}</span>
+                                    </div>
+                                    <br>
+
                                     <table id="watch_list" class="tablesorter">
                                         <thead>
                                             <tr>
@@ -159,7 +223,7 @@ $("#watch_list tbody tr").each(function(){
                                             </tr>
                                         </thead>
                                         <tbody>
-% for watch in watch_list:
+% for watch in pager.get_displays():
                                             <tr id="watch_list_row${watch.id}">
                                                 <td align="center">${watch.id |h}</td>
                                                 <td>${watch.plugin |h}</td>