ghorsington 4 роки тому
батько
коміт
0b539046c6
3 змінених файлів з 37 додано та 32 видалено
  1. 17 27
      src/app.py
  2. 14 4
      src/static/style/main.scss
  3. 6 1
      src/templates/project_view.html

+ 17 - 27
src/app.py

@@ -4,6 +4,8 @@ import os
 import json
 from typing import List
 import markdown as md
+from dataclasses import dataclass
+from dataclasses_json import dataclass_json
 
 app = Flask(__name__)
 assets = Environment(app)
@@ -18,48 +20,29 @@ assets.config['PYSCSS_ASSETS_ROOT'] = assets.directory
 assets.register('scss_all', scss)
 
 
+@dataclass
+@dataclass_json
 class ArtifactItem:
     file: str
     description: str
     width: int = 0
 
-    def __init__(self, file, description):
-        self.file = file
-        self.description = description
-
 
+@dataclass
+@dataclass_json
 class Artifact:
     id: str
     date: str
     changelog: str
     artifacts: List[ArtifactItem]
-
-    def __init__(self, id, date, changelog, artifacts):
-        self.id = id
-        self.date = date.strip()
-        self.changelog = changelog
-        self.artifacts = [ArtifactItem(**item)
-                          for item in artifacts]
-        maxwidth = max((len(a.file) for a in self.artifacts), default=0)
-        for a in self.artifacts:
-            a.width = maxwidth
-
-    @classmethod
-    def from_json(cls, json_str):
-        json_dict = json.loads(json_str)
-        return cls(**json_dict)
+    hash: str = None
 
 
+@dataclass
+@dataclass_json
 class ProjectInfo:
     name: str
-
-    def __init__(self, name):
-        self.name = name
-
-    @classmethod
-    def from_json(cls, json_str):
-        json_dict = json.loads(json_str)
-        return cls(**json_dict)
+    commit_url: str
 
 
 class Project:
@@ -79,6 +62,12 @@ class Project:
             try:
                 with open(info_file_path, "r", encoding="utf-8") as f:
                     artifact = Artifact.from_json(f.read())
+                    artifact.date = artifact.date.strip()
+                    maxwidth = max((len(a.file)
+                                    for a in artifact.artifacts), default=0)
+                    for a in artifact.artifacts:
+                        a.width = maxwidth
+
                     result.append(artifact)
             except:
                 continue
@@ -140,5 +129,6 @@ def index():
     projects = get_projects()
     return render_template("main.html", projects=projects)
 
+
 if __name__ == "__main__":
     app.run(host='0.0.0.0')

+ 14 - 4
src/static/style/main.scss

@@ -91,6 +91,7 @@ div.artifact-item {
   & > div.artifact-details {
     @extend .columns, .is-mobile;
 
+    background-color: hsl(0, 0%, 85%);
     user-select: none;
     align-items: center;
     margin-top: 0;
@@ -105,7 +106,10 @@ div.artifact-item {
 
     & > div.artifact-info {
       @extend .column;
-      background-color: hsl(0, 0%, 85%);
+
+      padding: 0;
+      padding-left: 1rem;
+      padding-right: 1rem;
 
       & > div.artifact-info-content {
         @extend .columns, .is-mobile;
@@ -119,9 +123,7 @@ div.artifact-item {
     }
 
     &:hover {
-      & > div.artifact-info {
-        background-color: hsl(0, 0%, 88%);
-      }
+      background-color: hsl(0, 0%, 88%);
 
       & > div.artifact-id {
         background-color: hsl(204, 86%, 58%);
@@ -145,3 +147,11 @@ div.artifact-item {
     }
   }
 }
+
+a.hash-button {
+  @extend .button, .is-info, .is-outlined;
+
+  font-family: "Lucida Console", Monaco, monospace;
+  margin-right: 0.5rem;
+  margin-left: 0;
+}

+ 6 - 1
src/templates/project_view.html

@@ -33,7 +33,12 @@
         </div>
         <div class="artifact-info">
             <div class="artifact-info-content" style="align-items: center">
-                <p>Build date: <span class="build-date">{{artifact.date}}</span></p>
+                <p>
+                    {%-if artifact.hash%}
+                    <a class="hash-button" href="{{selected_project.info.commit_url}}/{{artifact.hash}}">{{artifact.hash[:8]}}</a>
+                    {%-endif%}
+                    Build date: <span class="build-date">{{artifact.date}}</span>
+                </p>
                 <div class="dropdown-button">
                     <span class="icon-down-open"></span>
                 </div>