Prechádzať zdrojové kódy

Add KeepArtifacts option

Andrea Fazzi 5 rokov pred
rodič
commit
a513d98c16

+ 16 - 8
generator/generators/list/list.go

@@ -209,14 +209,22 @@ func (generator *ListGenerator) Run() {
 		}
 	}
 
-	log.Println("Uploading files to the cloud...")
-	src, err := ioutil.ReadFile(filepath.Join(outputPath, "elenco_docenti.pdf"))
-	if err != nil {
-		log.Println(err)
-	}
-	err = generator.ncClient.Upload(src, filepath.Join(cloudPath, "elenco_docenti.pdf"))
-	if err != nil {
-		log.Println(err)
+	if !job.Document.KeepArtifacts {
+		log.Println("Uploading resulting files to the cloud...")
+		src, err := ioutil.ReadFile(filepath.Join(outputPath, "elenco_docenti.pdf"))
+		if err != nil {
+			log.Println(err)
+		}
+		err = generator.ncClient.Upload(src, filepath.Join(cloudPath, "elenco_docenti.pdf"))
+		if err != nil {
+			log.Println(err)
+		}
+	} else {
+		log.Println("Uploading resulting files and artifacts to the cloud...")
+		_, err = generator.ncClient.UploadDir(filepath.Join(outputPath, "*"), cloudPath)
+		if err != nil {
+			log.Println(err)
+		}
 	}
 	log.Println("Files were uploaded to the cloud...")
 }

+ 7 - 0
orm/document.go

@@ -28,6 +28,8 @@ type Document struct {
 	GeneratorTypeID uint
 	GeneratorType   *GeneratorType
 
+	KeepArtifacts bool
+
 	Jobs []*Job
 
 	RunningJobs   []*Job
@@ -107,6 +109,9 @@ func UpdateDocument(args map[string]string, r *http.Request) (IDer, error) {
 		return nil, err
 	}
 
+	// FIXME: Should not be hard set.
+	document.(*Document).KeepArtifacts = false
+
 	err = renderer.Decode(document, r)
 	if err != nil {
 		return nil, err
@@ -116,10 +121,12 @@ func UpdateDocument(args map[string]string, r *http.Request) (IDer, error) {
 	if err != nil {
 		return nil, err
 	}
+
 	document, err = GetDocument(args)
 	if err != nil {
 		return nil, err
 	}
+
 	return document.(*Document), nil
 }
 

+ 8 - 0
templates/documents_add_update.html.tpl

@@ -48,6 +48,14 @@
       <input type="text" name="CloudPath" class="form-control" id="document_cloud_path" placeholder="Documents/" {{if .Options.Get "update"}} value="{{.Data.CloudPath}}" {{end}} required>
     </div>
 
+    <div class="form-check">
+      <input type="checkbox" name="KeepArtifacts" class="form-check-input" id="keep_artifacts" {{if .Options.Get "update"}}{{if .Data.KeepArtifacts}}checked{{end}}{{end}}>
+      <label class="form-check-label" for="exampleCheck1">Mantieni gli artefatti</label>
+      <small id="activity_group_hours_help_box" class="form-text text-muted">
+        Se selezionato carica sulla cartella remota gli artefatti derivati dalla produzione del documento (es: file di Markdown).
+      </small>        
+    </div>
+
         
     <div class="form-group">
       <label class="control-label" for="generator_type_id">Tipo di generatore</label>