From 36f9480837c3596381a3b5bd639a5709d2828719 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Sat, 7 Oct 2017 13:50:57 +1100 Subject: [PATCH] feat(matrix): add simple ui --- lib/pact_broker/ui/app.rb | 5 +++ lib/pact_broker/ui/controllers/matrix.rb | 27 ++++++++++++ lib/pact_broker/ui/view_models/matrix_line.rb | 42 +++++++++++++++++++ lib/pact_broker/ui/views/matrix/show.haml | 30 +++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 lib/pact_broker/ui/controllers/matrix.rb create mode 100644 lib/pact_broker/ui/view_models/matrix_line.rb create mode 100644 lib/pact_broker/ui/views/matrix/show.haml diff --git a/lib/pact_broker/ui/app.rb b/lib/pact_broker/ui/app.rb index bfc3e82e4..800882fce 100644 --- a/lib/pact_broker/ui/app.rb +++ b/lib/pact_broker/ui/app.rb @@ -1,5 +1,6 @@ require 'pact_broker/ui/controllers/relationships' require 'pact_broker/ui/controllers/groups' +require 'pact_broker/ui/controllers/matrix' require 'pact_broker/doc/controllers/app' module PactBroker @@ -21,6 +22,10 @@ def initialize run PactBroker::Doc::Controllers::App end + map "/the-matrix" do + run PactBroker::UI::Controllers::Matrix + end + map "/" do run PactBroker::UI::Controllers::Relationships end diff --git a/lib/pact_broker/ui/controllers/matrix.rb b/lib/pact_broker/ui/controllers/matrix.rb new file mode 100644 index 000000000..2df3dbd16 --- /dev/null +++ b/lib/pact_broker/ui/controllers/matrix.rb @@ -0,0 +1,27 @@ +require 'pact_broker/ui/controllers/base_controller' +require 'pact_broker/ui/view_models/matrix_line' +require 'haml' + +module PactBroker + module UI + module Controllers + class Matrix < Base + + include PactBroker::Services + + get "/provider/:provider_name/consumer/:consumer_name" do + lines = matrix_service.find consumer_name: params[:consumer_name], provider_name: params[:provider_name] + lines = lines.collect{|line| PactBroker::UI::ViewDomain::MatrixLine.new(line)} + locals = { + lines: lines, + title: "The Matrix", + consumer_name: params[:consumer_name], + provider_name: params[:provider_name] + } + haml :'matrix/show', {locals: locals, layout: :'layouts/main'} + end + + end + end + end +end diff --git a/lib/pact_broker/ui/view_models/matrix_line.rb b/lib/pact_broker/ui/view_models/matrix_line.rb new file mode 100644 index 000000000..9a7b47107 --- /dev/null +++ b/lib/pact_broker/ui/view_models/matrix_line.rb @@ -0,0 +1,42 @@ +require 'pact_broker/api/pact_broker_urls' +require 'pact_broker/ui/helpers/url_helper' +require 'pact_broker/date_helper' + +module PactBroker + module UI + module ViewDomain + class MatrixLine + + include PactBroker::Api::PactBrokerUrls + + def initialize line + @line = line + end + + def consumer_version_number + @line[:consumer_version_number] + end + + def provider_version_number + @line[:provider_version] + end + + def verification_status + case @line[:success] + when true then "Verified" + when false then "Failed" + else '' + end + end + + def verification_status_class + case @line[:success] + when true then 'success' + when false then 'danger' + else '' + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/pact_broker/ui/views/matrix/show.haml b/lib/pact_broker/ui/views/matrix/show.haml new file mode 100644 index 000000000..ab696b28f --- /dev/null +++ b/lib/pact_broker/ui/views/matrix/show.haml @@ -0,0 +1,30 @@ +%body + %link{rel: 'stylesheet', href: '/css/bootstrap.min.css'} + %link{rel: 'stylesheet', href: '/stylesheets/relationships.css'} + %script{type: 'text/javascript', src:'/javascripts/jquery-2.1.1.min.js'} + %script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'} + %script{type: 'text/javascript', src:'/js/bootstrap.min.js'} + +.container + %h1.page-header + = title + %table.table.table-bordered.table-striped{id: 'relationships'} + %thead + %th.consumer + = "#{consumer_name} version" + %span.glyphicon.glyphicon-sort.sort + %th.provider + = "#{provider_name} version" + %span.glyphicon.glyphicon-sort.sort + %th.verification-result + Verification + %tbody + - lines.each do | line | + %tr + %td.consumer-version + = line.consumer_version_number + %td.provider + = line.provider_version_number + %td.verification-result{class: line.verification_status_class} + = line.verification_status +