r2755 - getIPv4VServiceSearchResult(): return standard cell list w/help of getSearch...
authorDenis Ovsienko <infrastation@yandex.ru>
Fri, 15 May 2009 18:08:06 +0000 (18:08 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Fri, 15 May 2009 18:08:06 +0000 (18:08 +0000)
 - getIPv4PrefixSearchResult(): idem
 - getFileSearchResult(): idem
 - listCells(): employ getExplicitTagsOnly() like loadEntityTags() does
 - spotEntity(): idem
 - renderVSCell(): sayonara
 - renderIPv4VSCell(): sayonara, code merged into renderCell()
 - renderIPv4NetCell(): idem
 - renderFileCell(): idem
 - renderRackObject(): switch to renderCell()
 - renderIPv4ForObject(): idem
 - renderIPv4SLB(): idem
 - renderIPv4Network(): idem
 - renderSearchResults(): idem
 - renderRSPoolLBForm(): idem
 - renderRSPool(): idem
 - renderObjectSLB(): idem
 - renderFile(): idem
 - renderFilesPortlet(): idem
 - renderFilesForEntity(): idem

inc/database.php
inc/functions.php
inc/interface.php

index 53e31503719250494c7f01f348050ca9e39e8616..3a954c81ee31b6890c50d347ad0fcadf04a7c6db 100644 (file)
@@ -318,6 +318,7 @@ function listCells ($realm, $parent_id = 0)
        // Add necessary finish to the list before returning it.
        foreach (array_keys ($ret) as $entity_id)
        {
+               $ret[$entity_id]['etags'] = getExplicitTagsOnly ($ret[$entity_id]['etags']);
                $ret[$entity_id]['itags'] = getImplicitTags ($ret[$entity_id]['etags']);
                $ret[$entity_id]['atags'] = generateEntityAutoTags ($realm, $entity_id);
                switch ($realm)
@@ -385,6 +386,7 @@ function spotEntity ($realm, $id)
        unset ($result);
        if (!isset ($ret['realm'])) // no rows were returned
                return NULL;
+       $ret['etags'] = getExplicitTagsOnly ($ret['etags']);
        $ret['itags'] = getImplicitTags ($ret['etags']);
        $ret['atags'] = generateEntityAutoTags ($realm, $id);
        switch ($realm)
@@ -1498,17 +1500,17 @@ function searchByl2address ($port_l2address)
 
 function getIPv4PrefixSearchResult ($terms)
 {
-       $query = "select id, inet_ntoa(ip) as ip, mask, name from IPv4Network where ";
-       $or = '';
-       foreach (explode (' ', $terms) as $term)
-       {
-               $query .= $or . "name like '%${term}%'";
-               $or = ' or ';
-       }
-       $result = useSelectBlade ($query, __FUNCTION__);
+       $byname = getSearchResultByField
+       (
+               'IPv4Network',
+               array ('id'),
+               'name',
+               $terms,
+               'ip'
+       );
        $ret = array();
-       while ($row = $result->fetch (PDO::FETCH_ASSOC))
-               $ret[] = $row;
+       foreach ($byname as $row)
+               $ret[] = spotEntity ('ipv4net', $row['id']);
        return $ret;
 }
 
@@ -1546,17 +1548,17 @@ function getIPv4RSPoolSearchResult ($terms)
 
 function getIPv4VServiceSearchResult ($terms)
 {
-       $query = "select id, inet_ntoa(vip) as vip, vport, proto, name from IPv4VS where ";
-       $or = '';
-       foreach (explode (' ', $terms) as $term)
-       {
-               $query .= $or . "name like '%${term}%'";
-               $or = ' or ';
-       }
-       $result = useSelectBlade ($query, __FUNCTION__);
+       $byname = getSearchResultByField
+       (
+               'IPv4VS',
+               array ('id'),
+               'name',
+               $terms,
+               'vip'
+       );
        $ret = array();
-       while ($row = $result->fetch (PDO::FETCH_ASSOC))
-               $ret[] = $row;
+       foreach ($byname as $row)
+               $ret[] = spotEntity ('ipv4vs', $row['id']);
        return $ret;
 }
 
@@ -1598,7 +1600,7 @@ function getFileSearchResult ($terms)
        $byFilename = getSearchResultByField
        (
                'File',
-               array ('id', 'name', 'comment', 'type', 'size'),
+               array ('id'),
                'name',
                $terms,
                'name'
@@ -1606,7 +1608,7 @@ function getFileSearchResult ($terms)
        $byComment = getSearchResultByField
        (
                'File',
-               array ('id', 'name', 'comment', 'type', 'size'),
+               array ('id'),
                'comment',
                $terms,
                'name'
@@ -1619,7 +1621,10 @@ function getFileSearchResult ($terms)
                                unset ($byComment[$key2]);
                                continue 2;
                        }
-       return array_merge ($byFilename, $byComment);
+       $ret = array();
+       foreach (array_merge ($byFilename, $byComment) as $row)
+               $ret[] = spotEntity ('file', $row['id']);
+       return $ret;
 }
 
 function getSearchResultByField ($tname, $rcolumns, $scolumn, $terms, $ocolumn = '')
@@ -3320,6 +3325,8 @@ function getAllUnlinkedFiles ($entity_type = NULL, $entity_id = 0)
        return $ret;
 }
 
+// FIXME: return a standard cell list, so upper layer can iterate over
+// it conveniently.
 function getFilesOfEntity ($entity_type = NULL, $entity_id = 0)
 {
        if ($entity_type == NULL || $entity_id == 0)
index 7502387ec2bf061fe235835134f4f0499cc69459..998199ffecc351fcd8a168eac5a10146f6c59913 100644 (file)
@@ -632,6 +632,8 @@ function parseWikiLink ($line, $which, $strip_optgroup = FALSE)
                return $o_value;
 }
 
+// FIXME: only renderIPv4Address() is using this function, consider
+// phasing it out.
 function buildVServiceName ($vsinfo = NULL)
 {
        if ($vsinfo == NULL)
index d6f5efaa0a4830162f4478ad417389d98d2f0ea8..b014fc5510d39dbce15295f0ef9fd997bbf08f15 100644 (file)
@@ -997,7 +997,7 @@ function renderRackObject ($object_id)
                                else
                                {
                                        echo "<td class='${secondclass}'>";
-                                       renderIPv4NetCell ($netinfo);
+                                       renderCell ($netinfo);
                                        echo "</td>";
                                        // filter out self-allocation
                                        $other_routers = array();
@@ -1098,7 +1098,7 @@ function renderRackObject ($object_id)
                foreach ($pools as $vs_id => $info)
                {
                        echo "<tr valign=top class=row_${order}><td class=tdleft>";
-                       renderVSCell ($vs_id);
+                       renderCell (spotEntity ('ipv4vs', $vs_id));
                        echo "</td><td class=tdleft>";
                        renderRSPoolCell ($info['pool_id'], $info['pool_name']);
                        echo '</td><td class=tdleft>' . $info['rscount'] . '</td>';
@@ -1323,7 +1323,7 @@ function renderIPv4ForObject ($object_id)
                        else
                        {
                                echo '<td>';
-                               renderIPv4NetCell ($netinfo);
+                               renderCell ($netinfo);
                                echo '</td>';
                                // filter out self-allocation
                                $other_routers = array();
@@ -2121,7 +2121,7 @@ function renderIPv4SLB ()
                foreach ($summary as $vsid => $vsdata)
                {
                        echo "<tr class=row_${order}><td class=tdleft>";
-                       renderVSCell ($vsid);
+                       renderCell (spotEntity ('ipv4vs', $vsid));
                        echo "</td>";
                        foreach ($lblist as $lb_object_id)
                        {
@@ -2333,12 +2333,12 @@ function renderIPv4Network ($id)
                                echo '&uarr;';
                        $arrows--;
                        echo "</th><td class=tdleft>";
-                       renderIPv4NetCell ($ainfo);
+                       renderCell ($ainfo);
                        echo "</td></tr>";
                }
                echo "<tr><th width='50%' class=tdright>&rarr;</th>";
                echo "<td class=tdleft>";
-               renderIPv4NetCell ($range);
+               renderCell ($range);
                echo "</td></tr>";
                // FIXME: get and display nested networks
                // $theitem = pickLeaf ($ipv4tree, $id);
@@ -3042,10 +3042,10 @@ function renderSearchResults ()
                                case 'ipv4network':
                                        startPortlet ("<a href='${root}?page=ipv4space'>IPv4 networks</a>");
                                        echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
-                                       foreach ($what as $netinfo)
+                                       foreach ($what as $cell)
                                        {
                                                echo "<tr class=row_${order} valign=top><td>";
-                                               renderIPv4NetCell ($netinfo);
+                                               renderCell ($cell);
                                                echo "</td></tr>\n";
                                                $order = $nextorder[$order];
                                        }
@@ -3087,10 +3087,10 @@ function renderSearchResults ()
                                case 'ipv4vs':
                                        startPortlet ("<a href='${root}?page=ipv4vslist'>Virtual services</a>");
                                        echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
-                                       foreach ($what as $vsinfo)
+                                       foreach ($what as $cell)
                                        {
                                                echo "<tr class=row_${order}><td class=tdleft>";
-                                               renderIPv4VSCell ($vsinfo);
+                                               renderCell ($cell);
                                                echo "</td></tr>";
                                                $order = $nextorder[$order];
                                        }
@@ -3113,10 +3113,10 @@ function renderSearchResults ()
                                case 'file':
                                        startPortlet ("<a href='${root}?page=files'>Files</a>");
                                        echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
-                                       foreach ($what as $item)
+                                       foreach ($what as $cell)
                                        {
                                                echo "<tr class=row_${order}><td class=tdleft>";
-                                               renderFileCell ($item);
+                                               renderCell ($cell);
                                                echo "</td></tr>";
                                                $order = $nextorder[$order];
                                        }
@@ -4185,7 +4185,7 @@ function renderRSPoolLBForm ($pool_id)
                                echo "<td class=tdleft>";
                                renderLBCell ($object_id);
                                echo "</td><td class=tdleft>";
-                               renderVSCell ($vs_id);
+                               renderCell (spotEntity ('ipv4vs', $vs_id));
                                echo "</td><td><textarea name=vsconfig>${configs['vsconfig']}</textarea></td>";
                                echo "<td><textarea name=rsconfig>${configs['rsconfig']}</textarea></td><td>";
                                printImageHREF ('SAVE', 'Save changes', TRUE);
@@ -4303,7 +4303,7 @@ function renderRSPool ($pool_id)
                foreach ($vslist as $vs_id => $configs)
        {
                echo "<tr valign=top class=row_${order}><td class=tdleft><a href='".makeHref(array('page'=>'ipv4vs', 'vs_id'=>$vs_id))."'>";
-               renderVSCell ($vs_id);
+               renderCell (spotEntity ('ipv4vs', $vs_id));
                echo "</td><td>";
                renderLBCell ($object_id);
                echo "</td><td class=slbconf>${configs['vsconfig']}</td>";
@@ -5006,7 +5006,7 @@ function renderObjectSLB ($object_id)
                        printImageHREF ('delete', 'Unconfigure');
                        echo "</a></td>";
                        echo "</td><td class=tdleft>";
-                       renderVSCell ($vs_id);
+                       renderCell (spotEntity ('ipv4vs', $vs_id));
                        echo "</td><td class=tdleft>";
                        renderRSPoolCell ($vsinfo['pool_id'], $rsplist[$vsinfo['pool_id']]);
                        echo "</td><td><textarea name=vsconfig>${vsinfo['vsconfig']}</textarea></td>";
@@ -5284,7 +5284,7 @@ function renderFile ($file_id)
                                                renderCell ($userinfo);
                                        break;
                                case 'ipv4net':
-                                       renderIPv4NetCell (spotEntity ($link['entity_type'], $link['entity_id']));
+                                       renderCell (spotEntity ($link['entity_type'], $link['entity_id']));
                                        break;
                                default:
                                        echo formatEntityName ($link['entity_type']) . ': ';
@@ -5414,7 +5414,9 @@ function renderFilesPortlet ($entity_type = NULL, $entity_id = 0)
                foreach ($files as $file)
                {
                        echo "<tr valign=top><td class=tdleft>";
-                       renderFileCell ($file);
+                       // That's a bit of overkill and ought to be justified after
+                       // getFilesOfEntity() returns a standard cell list.
+                       renderCell (spotEntity ('file', $file['id']));
                        echo "</td><td class=tdleft>${file['comment']}</td></tr>";
                        if ('' != ($pcode = getFilePreviewCode ($file)))
                                echo "<tr><td colspan=2>${pcode}</td></tr>\n";
@@ -5467,7 +5469,7 @@ function renderFilesForEntity ($entity_id)
                foreach ($filelist as $file_id => $file)
                {
                        echo "<tr valign=top><td class=tdleft>";
-                       renderFileCell ($file);
+                       renderCell (spotEntity ('file', $file_id));
                        echo "</td><td class=tdleft>${file['comment']}</td><td class=tdcenter>";
                        echo "<a href='".makeHrefProcess(array('op'=>'unlinkFile', 'link_id'=>$file['link_id'], $id_name=>$entity_id))."'>";
                        printImageHREF ('CUT', 'Unlink file');
@@ -5564,41 +5566,68 @@ function printIPv4NetInfoTDs ($netinfo, $tdclass = 'tdleft', $indent = 0, $symbo
        echo "</td>";
 }
 
-function renderIPv4NetCell ($netinfo)
-{
-       global $root;
-       echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
-       printImageHREF ('NET');
-       echo '</td>';
-       echo "<td><a href='${root}?page=ipv4net&id=${netinfo['id']}'>${netinfo['ip']}/${netinfo['mask']}</a></td></tr>";
-       if (strlen ($netinfo['name']))
-               echo "<tr><td><strong>" . niftyString ($netinfo['name']) . "</strong></td></tr>";
-       else
-               echo "<tr><td class=sparenetwork>no name</td></tr>";
-       echo '<td>';
-       $tags = loadEntityTags ('ipv4net', $netinfo['id']);
-       echo count ($tags) ? ("<small>" . serializeTags ($tags) . "</small>") : '&nbsp;';
-       echo "</td></tr></table>";
-}
-
 function renderCell ($cell)
 {
+       global $root;
        switch ($cell['realm'])
        {
        case 'user':
                renderUserCell ($cell);
                break;
        case 'file':
-               renderFileCell ($cell);
+               echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
+               switch ($cell['type'])
+               {
+                       case 'text/plain':
+                               printImageHREF ('text file');
+                               break;
+                       case 'image/jpeg':
+                       case 'image/png':
+                       case 'image/gif':
+                               printImageHREF ('image file');
+                               break;
+                       default:
+                               printImageHREF ('empty file');
+                               break;
+               }
+               echo "</td><td>";
+               printf ("<a href='${root}?page=file&file_id=%s'><strong>%s</strong></a>", $cell['id'], niftyString ($cell['name']));
+               echo "</td><td rowspan=3 valign=top>";
+               if (isset ($cell['links']) and count ($cell['links']))
+                       printf ("<small>%s</small>", serializeFileLinks ($cell['links']));
+               echo "</td></tr><tr><td>";
+               echo count ($cell['etags']) ? ("<small>" . serializeTags ($cell['etags']) . "</small>") : '&nbsp;';
+               echo "</td></tr><tr><td><a href='${root}download.php?file_id=${cell['id']}'>";
+               printImageHREF ('download', 'Download file');
+               echo '</a>&nbsp;';
+               echo formatFileSize ($cell['size']);
+               echo "</td></tr></table>";
                break;
        case 'ipv4vs':
-               renderIPv4VSCell ($cell);
+               echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
+               printImageHREF ('VS');
+               echo "</td><td>";
+               echo "<a href='${root}?page=ipv4vs&vs_id=${cell['id']}'>";
+               echo $cell['dname'] . "</a></td></tr><tr><td>";
+               echo $cell['name'] . '</td></tr><tr><td>';
+               echo count ($cell['etags']) ? ("<small>" . serializeTags ($cell['etags']) . "</small>") : '&nbsp;';
+               echo "</td></tr></table>";
                break;
        case 'ipv4rspool':
                renderRSPoolCell ($cell['id'], $cell['name']);
                break;
        case 'ipv4net':
-               renderIPv4NetCell ($cell);
+               echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
+               printImageHREF ('NET');
+               echo '</td>';
+               echo "<td><a href='${root}?page=ipv4net&id=${cell['id']}'>${cell['ip']}/${cell['mask']}</a></td></tr>";
+               if (strlen ($cell['name']))
+                       echo "<tr><td><strong>" . niftyString ($cell['name']) . "</strong></td></tr>";
+               else
+                       echo "<tr><td class=sparenetwork>no name</td></tr>";
+               echo '<td>';
+               echo count ($cell['etags']) ? ("<small>" . serializeTags ($cell['etags']) . "</small>") : '&nbsp;';
+               echo "</td></tr></table>";
                break;
        default:
                showError ('odd data', __FUNCTION__);
@@ -5650,30 +5679,6 @@ function renderRSPoolCell ($pool_id, $pool_name)
        echo "</small></td></tr></table>";
 }
 
-// FIXME: migrate to renderIPv4VSCell()
-function renderVSCell ($vs_id)
-{
-       renderIPv4VSCell (spotEntity ('ipv4vs', $vs_id));
-}
-
-function renderIPv4VSCell ($vsinfo)
-{
-       global $root;
-       echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
-       printImageHREF ('VS');
-       echo "</td><td>";
-       echo "<a href='${root}?page=ipv4vs&vs_id=${vsinfo['id']}'>";
-       // FIXME: this is a workaround
-       if (!isset ($vsinfo['dname']))
-               $vsinfo['dname'] = buildVServiceName ($vsinfo);
-       echo $vsinfo['dname'] . "</a></td></tr><tr><td>";
-       echo $vsinfo['name'];
-       echo '</td></tr><tr><td>';
-       $tags = loadEntityTags ('ipv4vs', $vsinfo['id']);
-       echo count ($tags) ? ("<small>" . serializeTags ($tags) . "</small>") : '&nbsp;';
-       echo "</td></tr></table>";
-}
-
 function renderRouterCell ($dottedquad, $ifname, $object_id, $object_dname)
 {
        global $root;
@@ -5689,40 +5694,6 @@ function renderRouterCell ($dottedquad, $ifname, $object_id, $object_dname)
        echo "</small></td></tr></table>";
 }
 
-function renderFileCell ($fileinfo)
-{
-       global $root;
-       echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
-       switch ($fileinfo['type'])
-       {
-               case 'text/plain':
-                       printImageHREF ('text file');
-                       break;
-               case 'image/jpeg':
-               case 'image/png':
-               case 'image/gif':
-                       printImageHREF ('image file');
-                       break;
-               default:
-                       printImageHREF ('empty file');
-                       break;
-       }
-       echo "</td><td>";
-       printf ("<a href='${root}?page=file&file_id=%s'><strong>%s</strong></a>", $fileinfo['id'], niftyString ($fileinfo['name']));
-       echo "</td><td rowspan=3 valign=top>";
-       if (isset ($fileinfo['links']) and count ($fileinfo['links']))
-               printf ("<small>%s</small>", serializeFileLinks ($fileinfo['links']));
-       echo "</td></tr><tr><td>";
-       if (!isset ($fileinfo['etags']))
-               $fileinfo['etags'] = loadEntityTags ('file', $fileinfo['id']);
-       echo count ($fileinfo['etags']) ? ("<small>" . serializeTags ($fileinfo['etags']) . "</small>") : '&nbsp;';
-       echo "</td></tr><tr><td><a href='${root}download.php?file_id=${fileinfo['id']}'>";
-       printImageHREF ('download', 'Download file');
-       echo '</a>&nbsp;';
-       echo formatFileSize ($fileinfo['size']);
-       echo "</td></tr></table>";
-}
-
 // Return HTML code necessary to show a preview of the file give. Return an empty string,
 // if a preview cannot be shown
 function getFilePreviewCode ($file)