Skip to content

Commit

Permalink
ux(): began work on updating data source list to cards view
Browse files Browse the repository at this point in the history
  • Loading branch information
torkelo committed Mar 15, 2016
1 parent 1abdd17 commit e4c0c39
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 50 deletions.
19 changes: 16 additions & 3 deletions pkg/api/datasources.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package api

import (
"sort"

"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/plugins"
//"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models"
Expand All @@ -17,9 +20,10 @@ func GetDataSources(c *middleware.Context) {
return
}

result := make([]*dtos.DataSource, len(query.Result))
for i, ds := range query.Result {
result[i] = &dtos.DataSource{
result := make(dtos.DataSourceList, 0)
for _, ds := range query.Result {

dsItem := dtos.DataSource{
Id: ds.Id,
OrgId: ds.OrgId,
Name: ds.Name,
Expand All @@ -32,8 +36,17 @@ func GetDataSources(c *middleware.Context) {
BasicAuth: ds.BasicAuth,
IsDefault: ds.IsDefault,
}

if plugin, exists := plugins.DataSources[ds.Type]; exists {
dsItem.TypeLogoUrl = plugin.Info.Logos.Small
} else {
dsItem.TypeLogoUrl = "public/img/plugin-default-logo_dark.svg"
}

result = append(result, dsItem)
}

sort.Sort(result)
c.JSON(200, result)
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/api/dtos/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type DataSource struct {
OrgId int64 `json:"orgId"`
Name string `json:"name"`
Type string `json:"type"`
TypeLogoUrl string `json:"typeLogoUrl"`
Access m.DsAccess `json:"access"`
Url string `json:"url"`
Password string `json:"password"`
Expand All @@ -75,6 +76,20 @@ type DataSource struct {
JsonData *simplejson.Json `json:"jsonData,omitempty"`
}

type DataSourceList []DataSource

func (slice DataSourceList) Len() int {
return len(slice)
}

func (slice DataSourceList) Less(i, j int) bool {
return slice[i].Name < slice[j].Name
}

func (slice DataSourceList) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
}

type MetricQueryResultDto struct {
Data []MetricQueryResultDataDto `json:"data"`
}
Expand Down
116 changes: 70 additions & 46 deletions public/app/features/plugins/partials/ds_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,79 @@ <h1>Data Sources</h1>
</a>
</div>

<br>
<section class="card-section" layout-mode>
<layout-selector></layout-selector>

<div ng-if="ctrl.datasources.length === 0">
<em>No data sources defined</em>
</div>

<table class="filter-table" ng-if="ctrl.datasources.length > 0">
<thead>
<tr>
<th><strong>name</strong></th>
<th><strong>type</strong></th>
<th><strong>url</strong></th>
<th style="width: 60px;"></th>
<th style="width: 85px;"></th>
<th style="width: 44px;"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="ds in ctrl.datasources">
<td>
<ol class="card-list" >
<li class="card-item-wrapper" ng-repeat="ds in ctrl.datasources">
<div class="card-item" >
<div class="card-item-header">
<i class="icon-gf icon-gf-{{ds.type}}"></i>
{{ds.type}}
</div>
<div class="card-item-body">
<a href="datasources/edit/{{ds.id}}">
<i class="icon-gf inline-icon-gf icon-gf-datasources"></i> &nbsp; {{ds.name}}
</a>
</td>
<td>
<span>{{ds.type}}</span>
</td>
<td>
<span>{{ds.url}}</span>
</td>
<td class="text-center">
<span ng-if="ds.isDefault">
<span class="btn btn-secondary btn-mini">default</span>
</span>
</td>
<td class="text-right">
<a href="datasources/edit/{{ds.id}}" class="btn btn-inverse btn-small">
<i class="fa fa-edit"></i>
Edit
</a>
</td>
<td class="text-right">
<a ng-click="ctrl.removeDataSource(ds)" class="btn btn-danger btn-small">
<i class="fa fa-remove"></i>
<figure class="card-item-figure">
<img ng-src="{{ds.typeLogoUrl}}">
</figure>
</a>
</td>
</tr>
</tbody>
</table>
<div class="card-item-details">
<a class="card-item-name" href="datasources/edit/{{ds.id}}/">{{ds.name}}</a>
<div class="card-item-sub-name">{{ds.url}}</div>
</div>
</div>
</div>
</li>
</ol>
</section>

<div ng-if="ctrl.datasources.length === 0">
<em>No data sources defined</em>
</div>

<table class="filter-table" ng-if="ctrl.datasources.length > 0">
<thead>
<tr>
<th><strong>name</strong></th>
<th><strong>type</strong></th>
<th><strong>url</strong></th>
<th style="width: 60px;"></th>
<th style="width: 85px;"></th>
<th style="width: 44px;"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="ds in ctrl.datasources">
<td>
<a href="datasources/edit/{{ds.id}}">
<i class="icon-gf inline-icon-gf icon-gf-datasources"></i> &nbsp; {{ds.name}}
</a>
</td>
<td>
<span>{{ds.type}}</span>
</td>
<td>
<span>{{ds.url}}</span>
</td>
<td class="text-center">
<span ng-if="ds.isDefault">
<span class="btn btn-secondary btn-mini">default</span>
</span>
</td>
<td class="text-right">
<a href="datasources/edit/{{ds.id}}" class="btn btn-inverse btn-small">
<i class="fa fa-edit"></i>
Edit
</a>
</td>
<td class="text-right">
<a ng-click="ctrl.removeDataSource(ds)" class="btn btn-danger btn-small">
<i class="fa fa-remove"></i>
</a>
</td>
</tr>
</tbody>
</table>

</div>
</div>
2 changes: 1 addition & 1 deletion public/app/features/plugins/partials/plugin_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h1>Plugins</h1>
<img ng-src="{{plugin.info.logos.small}}">
</figure>
<div class="card-item-details">
<div class="card-item-name" href="plugins/{{plugin.id}}/edit">{{plugin.name}}</div>
<div class="card-item-name">{{plugin.name}}</div>
<div class="card-item-sub-name">By {{plugin.info.author.name}}</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions public/sass/components/_cards.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@

.card-item-header {
color: $text-color-weak;
text-transform: uppercase;
margin-bottom: $spacer;
font-size: $font-size-sm;
font-weight: bold;
}

.card-item-name {
Expand Down

0 comments on commit e4c0c39

Please sign in to comment.