Skip to content

Commit

Permalink
Small improvements for the overview view
Browse files Browse the repository at this point in the history
  • Loading branch information
michelvocks committed Jun 12, 2018
1 parent 0083801 commit b9095f3
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 15 deletions.
71 changes: 56 additions & 15 deletions frontend/client/views/overview/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
<div class="notification content-article">
<div class="status-display-success"></div>
<div class="outer-box">
<div class="outer-box-icon-image">
<img :src="getImagePath(pipeline.type)" class="outer-box-image">
</div>
<div>
<router-link :to="{ path: '/pipeline/detail', query: { pipelineid: pipeline.id }}" class="subtitle">{{ pipeline.name }}</router-link>
</div>
<div>
<hr style="color: lightgrey;">
<a class="button is-primary" @click="startPipeline(pipeline.id)">
<span class="icon">
<i class="fa fa-play-circle"></i>
</span>
<span>Start Pipeline</span>
</a>
<router-link :to="{ path: '/pipeline/detail', query: { pipelineid: pipeline.p.id }}" class="hoveraction">
<div class="outer-box-icon-image">
<img :src="getImagePath(pipeline.p.type)" class="outer-box-image">
</div>
<div>
<span class="subtitle">{{ pipeline.p.name }}</span>
</div>
</router-link>
<hr class="pipeline-hr">
<div class="pipeline-info">
<span>Duration: {{ pipeline.r.startdate }}</span><br />
<span>Started: {{ pipeline.r.finishdate }}</span><br />
<div class="pipelinegrid-footer">
<a class="button is-primary" @click="startPipeline(pipeline.p.id)" style="width: 250px;">
<span class="icon">
<i class="fa fa-play-circle"></i>
</span>
<span>Start Pipeline</span>
</a>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -55,7 +61,7 @@ export default {
methods: {
fetchData () {
this.$http
.get('/api/v1/pipeline', { showProgressBar: false })
.get('/api/v1/pipeline/latest', { showProgressBar: false })
.then(response => {
if (response.data) {
this.pipelines = response.data
Expand Down Expand Up @@ -151,4 +157,39 @@ export default {
transform: translate(-50%, -50%);
}
.hoveraction:hover .outer-box-icon-image {
border-color: #4da2fc !important;
}
.hoveraction:hover .subtitle {
color: #4da2fc !important;
text-decoration: underline;
text-decoration-color: #4da2fc !important;
}
.pipeline-hr {
position: absolute;
width: 325px;
margin-left: -13px;
margin-top: 18px;
background-image: linear-gradient(
to right,
black 33%,
rgba(255, 255, 255, 0) 0%
);
background-position: bottom;
background-size: 3px 1px;
background-repeat: repeat-x;
}
.pipeline-info {
padding-top: 33px;
}
.pipelinegrid-footer {
margin: auto;
width: 82%;
padding-top: 20px;
}
</style>
2 changes: 2 additions & 0 deletions handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ func InitHandlers(e *echo.Echo, store *store.Store, scheduler *scheduler.Schedul
e.GET(p+"pipeline", PipelineGetAll)
e.GET(p+"pipeline/:pipelineid", PipelineGet)
e.POST(p+"pipeline/:pipelineid/start", PipelineStart)
e.GET(p+"pipeline/latest", PipelineGetAllWithLatestRun)

// PipelineRun
e.GET(p+"pipelinerun/:pipelineid/:runid", PipelineRunGet)
e.GET(p+"pipelinerun/:pipelineid", PipelineGetAllRuns)
e.GET(p+"pipelinerun/:pipelineid/latest", PipelineGetLatestRun)
e.GET(p+"pipelinerun/:pipelineid/:runid/log", GetJobLogs)

// Middleware
Expand Down
36 changes: 36 additions & 0 deletions handlers/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,39 @@ func PipelineStart(c echo.Context) error {
// Pipeline not found
return c.String(http.StatusNotFound, errPipelineNotFound.Error())
}

type getAllWithLatestRun struct {
Pipeline gaia.Pipeline `json:"p"`
PipelineRun gaia.PipelineRun `json:"r"`
}

// PipelineGetAllWithLatestRun returns the latest of all registered pipelines
// included with the latest run.
func PipelineGetAllWithLatestRun(c echo.Context) error {
// Get all active pipelines
var pipelines []gaia.Pipeline
for pipeline := range pipeline.GlobalActivePipelines.Iter() {
pipelines = append(pipelines, pipeline)
}

// Iterate all pipelines
var pipelinesWithLatestRun []getAllWithLatestRun
for _, pipeline := range pipelines {
// Get the latest run by the given pipeline id
run, err := storeService.PipelineGetLatestRun(pipeline.ID)
if err != nil {
return c.String(http.StatusInternalServerError, err.Error())
}

// Create new return obj
g := getAllWithLatestRun{
Pipeline: pipeline,
PipelineRun: *run,
}

// Append
pipelinesWithLatestRun = append(pipelinesWithLatestRun, g)
}

return c.JSON(http.StatusOK, pipelinesWithLatestRun)
}
17 changes: 17 additions & 0 deletions handlers/pipeline_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ func PipelineGetAllRuns(c echo.Context) error {
return c.JSON(http.StatusOK, runs)
}

// PipelineGetLatestRun returns the latest run of a pipeline, given by id.
func PipelineGetLatestRun(c echo.Context) error {
// Convert string to int because id is int
pipelineID, err := strconv.Atoi(c.Param("pipelineid"))
if err != nil {
return c.String(http.StatusBadRequest, errInvalidPipelineID.Error())
}

// Get the latest run by the given pipeline id
run, err := storeService.PipelineGetLatestRun(pipelineID)
if err != nil {
return c.String(http.StatusInternalServerError, err.Error())
}

return c.JSON(http.StatusOK, run)
}

// GetJobLogs returns logs and new start position for the given job.
// If no jobID is given, a collection of all jobs logs will be returned.
//
Expand Down
33 changes: 33 additions & 0 deletions store/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,36 @@ func (s *Store) PipelineGetAllRuns(pipelineID int) ([]gaia.PipelineRun, error) {
})
})
}

// PipelineGetLatestRun returns the latest run by the given pipeline id.
func (s *Store) PipelineGetLatestRun(pipelineID int) (*gaia.PipelineRun, error) {
var run *gaia.PipelineRun

return run, s.db.View(func(tx *bolt.Tx) error {
// Get Bucket
b := tx.Bucket(pipelineRunBucket)

// Iterate all pipeline runs.
return b.ForEach(func(k, v []byte) error {
// create single run object
r := &gaia.PipelineRun{}

// Unmarshal
err := json.Unmarshal(v, r)
if err != nil {
return err
}

// Is this a run from our pipeline?
if r.PipelineID == pipelineID {
// Check if this is the latest run
if run == nil || run.StartDate.Before(r.StartDate) {
// set it
run = r
}
}

return nil
})
})
}

0 comments on commit b9095f3

Please sign in to comment.