Skip to content

Commit

Permalink
Updated Home page
Browse files Browse the repository at this point in the history
  • Loading branch information
MeNsaaH committed Oct 10, 2020
1 parent 650ae04 commit 614edad
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 38 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 8,7 @@ require (
github.com/gin-gonic/gin v1.6.3
github.com/go-co-op/gocron v0.3.1
github.com/jinzhu/now v1.1.1
github.com/labstack/gommon v0.3.0
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/spf13/viper v1.7.0
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 206,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc lOruYdAhDwPK9wf0OL7NoOu k=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1: 8 nEpDfqqsY g338gtMEUOtuK 4dEMhiQEgxpxOKII=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U lTReE5YruASi9Al49XbQIvNi/34Woo=
Expand Down Expand Up @@ -319,6 321,10 @@ github.com/ugorji/go v1.1.7 h1:/68gy2h 1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax UKWsSmolVDwsd 7N3ZtXu yMGCf907BLYF3GoBXY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd c6RKGD0IfU8WdUSz8=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL uU=
Expand Down
3 changes: 0 additions & 3 deletions provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 62,12 @@ func NewProvider() (*types.Provider, error) {

ec2Manager := newEC2Manager(cfg, logFile)
s3Manager := newS3Manager(cfg, logFile)
fmt.Println("Managers: ", s3Manager, ec2Manager)

resourceManagers = map[string]*types.ResourceManager{
ec2Manager.Name: &ec2Manager,
s3Manager.Name: &s3Manager,
}

fmt.Println(resourceManagers)

aws.ResourceManagers = resourceManagers
return &aws, nil
}
23 changes: 23 additions & 0 deletions web/controllers/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 4,33 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/labstack/gommon/log"

"github.com/mensaah/reka/types"
"github.com/mensaah/reka/web/models"
)

//HomeGet handles GET / route
func HomeGet(c *gin.Context) {
var r types.Resource

db := models.GetDB()
h := DefaultH(c)
// TODO Specify Provider to query from
// provider := strings.ToLower(c.Param("provider")) || config.GetProviders()[0]
// Filter where resource Manager is for a particular provider

h["TrackedResourceCount"] = db.Not("state = ?", types.Destroyed).Find(&r).RowsAffected
h["RunningResourceCount"] = db.Where("state = ?", types.Running).Find(&r).RowsAffected
h["StoppedResourceCount"] = db.Where("state = ?", types.Stopped).Find(&r).RowsAffected
h["DestroyedResourceCount"] = db.Where("state = ?", types.Destroyed).Find(&r).RowsAffected

// Get Recent Resource Updates
var recentResourceUpdates []types.Resource
if err := db.Order("updated_at desc").Limit(10).Find(&recentResourceUpdates); err != nil {
log.Error("DB Error: ", err.Error)
}
h["RecentResourceUpdates"] = recentResourceUpdates

c.HTML(http.StatusOK, "index", h)
}
1 change: 1 addition & 0 deletions web/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 60,7 @@ func main() {
// router.Use(controllers.ContextData())

router.GET("/", controllers.HomeGet)
router.GET("/provider/:provider", controllers.HomeGet)
// router.NoRoute(controllers.NotFound)
// router.NoMethod(controllers.MethodNotAllowed)

Expand Down
48 changes: 13 additions & 35 deletions web/templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 22,7 @@
<!-- small box -->
<div class="small-box bg-info">
<div class="inner">
<h3>150</h3>
<h3>{{ .TrackedResourceCount }}</h3>

<p>Tracked Resource</p>
</div>
Expand All @@ -37,7 37,7 @@
<!-- small box -->
<div class="small-box bg-success">
<div class="inner">
<h3>53</h3>
<h3>{{ .RunningResourceCount }}</h3>

<p>Running Resources</p>
</div>
Expand All @@ -52,7 52,7 @@
<!-- small box -->
<div class="small-box bg-warning">
<div class="inner">
<h3>44</h3>
<h3>{{ .StoppedResourceCount }}</h3>

<p>Stopped Resources</p>
</div>
Expand All @@ -67,7 67,7 @@
<!-- small box -->
<div class="small-box bg-danger">
<div class="inner">
<h3>65</h3>
<h3>{{ .DestroyedResourceCount }}</h3>

<p>Destroyed Resources</p>
</div>
Expand Down Expand Up @@ -101,48 101,26 @@
<thead>
<tr>
<th>Resource ID</th>
<th>Region</th>
<th>Resource Type</th>
<th>Status</th>
<th>Time status changed</th>
</tr>
</thead>
<tbody>

{{range .RecentResourceUpdates}}
<tr>
<td><a href="pages/examples/invoice.html">OR9842</a></td>
<td>EC2</td>
<td><span class="badge badge-success">Running</span></td>
<td><a href="pages/examples/invoice.html">{{ .UUID }}</a></td>
<td>{{ .Region }}</td>
<td>{{ .ManagerName }}</td>
<td><span class="badge badge-success">{{ .State }}</span></td>
<td>
<div class="sparkbar" data-color="#00a65a" data-height="20">
10/10/2020 8:49:12</div>
</td>
</tr>
<tr>
<td><a href="pages/examples/invoice.html">OR1848</a></td>
<td>EBS</td>
<td><span class="badge badge-warning">Pending</span></td>
<td>
<div class="sparkbar" data-color="#f39c12" data-height="20">
10/10/2020 8:57:12<div>
</td>
</tr>
<tr>
<td><a href="pages/examples/invoice.html">OR7429</a></td>
<td>EC2</td>
<td><span class="badge badge-danger">Stopped</span></td>
<td>
<div class="sparkbar" data-color="#f56954" data-height="20">
10/10/2020 10:08:18</div>
</td>
</tr>
<tr>
<td><a href="pages/examples/invoice.html">OR7429</a></td>
<td>EKS</td>
<td><span class="badge badge-info">Starting</span></td>
<td>
<div class="sparkbar" data-color="#00c0ef" data-height="20">
10/10/2020 15:10:18</div>
{{ .UpdatedAt.Format "Jan 02, 2006 15:04:05 UTC" }}</div>
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
Expand Down

0 comments on commit 614edad

Please sign in to comment.