From f675c0de255a6da6a7dfeb7ba5aa7b08c5194e68 Mon Sep 17 00:00:00 2001
From: fkiefer <none@none>
Date: Mon, 6 Feb 2017 15:07:10 +0100
Subject: [PATCH] OO-2483 add error key icons and other icons to video tables

---
 .../modules/video/ui/QualityTableRow.java     |  8 +--
 .../ui/TranscodingErrorIconRenderer.java      | 69 +++++++++++++++++++
 .../ui/VideoAdminTranscodingController.java   |  6 +-
 .../ui/VideoQualityTableFormController.java   | 11 +--
 4 files changed, 84 insertions(+), 10 deletions(-)
 create mode 100644 src/main/java/org/olat/modules/video/ui/TranscodingErrorIconRenderer.java

diff --git a/src/main/java/org/olat/modules/video/ui/QualityTableRow.java b/src/main/java/org/olat/modules/video/ui/QualityTableRow.java
index e9b21504baf..c6f0cdb1106 100644
--- a/src/main/java/org/olat/modules/video/ui/QualityTableRow.java
+++ b/src/main/java/org/olat/modules/video/ui/QualityTableRow.java
@@ -33,7 +33,7 @@ public class QualityTableRow {
 
 	private FormLink resolution;
 	private String dimension;
-	private String size;
+	private Object[] size;
 	private String format;
 	private FormLink deleteLink;
 
@@ -48,7 +48,7 @@ public class QualityTableRow {
 	 * @param viewLink
 	 * @param deleteLink FormLink for delete row and corresponding Videodata or null if no deleteLink should be shown
 	 */
-	public QualityTableRow(FormLink resolution, String dimension, String size, String format, FormLink deleteLink) {
+	public QualityTableRow(FormLink resolution, String dimension, Object[] size, String format, FormLink deleteLink) {
 		this.resolution = resolution;
 		this.resolution.setIconLeftCSS("o_icon o_icon-fw o_icon_preview");
 		this.dimension = dimension;
@@ -73,11 +73,11 @@ public class QualityTableRow {
 		this.dimension = dimension;
 	}
 
-	public String getSize() {
+	public Object[] getSize() {
 		return size;
 	}
 
-	public void setSize(String size) {
+	public void setSize(Object[] size) {
 		this.size = size;
 	}
 
diff --git a/src/main/java/org/olat/modules/video/ui/TranscodingErrorIconRenderer.java b/src/main/java/org/olat/modules/video/ui/TranscodingErrorIconRenderer.java
new file mode 100644
index 00000000000..2fa61f311b9
--- /dev/null
+++ b/src/main/java/org/olat/modules/video/ui/TranscodingErrorIconRenderer.java
@@ -0,0 +1,69 @@
+/**
+ * <a href="http://www.openolat.org">
+ * OpenOLAT - Online Learning and Training</a><br>
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); <br>
+ * you may not use this file except in compliance with the License.<br>
+ * You may obtain a copy of the License at the
+ * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
+ * <p>
+ * Unless required by applicable law or agreed to in writing,<br>
+ * software distributed under the License is distributed on an "AS IS" BASIS, <br>
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
+ * See the License for the specific language governing permissions and <br>
+ * limitations under the License.
+ * <p>
+ * Initial code contributed and copyrighted by<br>
+ * frentix GmbH, http://www.frentix.com
+ * <p>
+ */
+package org.olat.modules.video.ui;
+
+import org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiCellRenderer;
+import org.olat.core.gui.components.table.IconCssCellRenderer;
+
+/**
+ * Initial date: 06.02.2017
+ * @author fkiefer, fabian.kiefer@frentix.com, http://www.frentix.com
+ */
+public class TranscodingErrorIconRenderer extends IconCssCellRenderer implements FlexiCellRenderer {
+	
+
+	@Override
+	protected String getCssClass(Object val) {
+		if(val == null) {
+			return null;
+		}
+		if(val instanceof Object[]) {
+			Object[] value = (Object[])val;
+			Integer status = (Integer)value[0];
+			switch(status) {
+				case -2: return "o_icon o_icon_warn o_icon-fw";
+				case -3: case -4: return "o_icon o_icon_error o_icon-fw";
+				default: return null;
+			}
+		}
+		return null;
+	}
+
+	@Override
+	protected String getCellValue(Object val) {
+		if(val == null) {
+			return null;
+		}
+		if(val instanceof Object[]) {
+			Object[] value = (Object[])val;
+			String desc = (String)value[1];
+			return desc;
+		}
+		return null;
+	}
+
+	@Override
+	protected String getHoverText(Object val) {
+		return getCellValue(val);
+	}
+
+	
+}
+
diff --git a/src/main/java/org/olat/modules/video/ui/VideoAdminTranscodingController.java b/src/main/java/org/olat/modules/video/ui/VideoAdminTranscodingController.java
index fb136155b46..01bcb593180 100644
--- a/src/main/java/org/olat/modules/video/ui/VideoAdminTranscodingController.java
+++ b/src/main/java/org/olat/modules/video/ui/VideoAdminTranscodingController.java
@@ -94,9 +94,11 @@ public class VideoAdminTranscodingController extends FormBasicController {
 		transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.failedTranscodings));
 		transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.missingTranscodings));
 		transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.transcode, "quality.transcode", 
-				new BooleanCellRenderer(new StaticFlexiCellRenderer(translate("quality.transcode"), "quality.transcode"), null)));
+				new BooleanCellRenderer(new StaticFlexiCellRenderer(translate("quality.transcode"), "quality.transcode",
+						"", "o_icon o_icon_refresh o_icon-fw"), null)));
 		transcodingModel.addFlexiColumnModel(new DefaultFlexiColumnModel(TranscodingCols.delete, "quality.delete", 
-				new BooleanCellRenderer(new StaticFlexiCellRenderer(translate("quality.delete"), "quality.delete"), null)));
+				new BooleanCellRenderer(new StaticFlexiCellRenderer(translate("quality.delete"), "quality.delete",
+						"", "o_icon o_icon_delete_item o_icon-fw"), null)));
 		tableModel = new TranscodingTableModel(transcodingModel, getTranslator());
 		
 		transcodingTable = uifactory.addTableElement(getWindowControl(), "table", tableModel, getTranslator(), formLayout);
diff --git a/src/main/java/org/olat/modules/video/ui/VideoQualityTableFormController.java b/src/main/java/org/olat/modules/video/ui/VideoQualityTableFormController.java
index 1cf1a788ff5..fcfd220e18f 100644
--- a/src/main/java/org/olat/modules/video/ui/VideoQualityTableFormController.java
+++ b/src/main/java/org/olat/modules/video/ui/VideoQualityTableFormController.java
@@ -91,7 +91,7 @@ public class VideoQualityTableFormController extends FormBasicController {
 		FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
 		columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(QualityTableCols.resolution));
 		columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(QualityTableCols.dimension));
-		columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(QualityTableCols.size));
+		columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(QualityTableCols.size, new TranscodingErrorIconRenderer()));
 		columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(QualityTableCols.format));
 		columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(QualityTableCols.delete));
 
@@ -106,7 +106,8 @@ public class VideoQualityTableFormController extends FormBasicController {
 		VideoMeta videoMetadata = videoManager.getVideoMetadata(videoResource);
 		// Add master video file
 		FormLink previewMasterLink = uifactory.addFormLink("view", "viewQuality", "quality.master", "quality.master", flc, Link.LINK);
-		rows.add(new QualityTableRow(previewMasterLink, videoMetadata.getWidth() +"x"+ videoMetadata.getHeight(), Formatter.formatBytes(videoManager.getVideoFile(videoResource).length()), "mp4",null));
+		Object[] statusMaster = new Object[]{100, Formatter.formatBytes(videoManager.getVideoFile(videoResource).length())};
+		rows.add(new QualityTableRow(previewMasterLink, videoMetadata.getWidth() +"x"+ videoMetadata.getHeight(), statusMaster, "mp4",null));
 		// Add all the transcoded versions
 		List<VideoTranscoding> videoTranscodings = videoManager.getVideoTranscodings(videoResource);
 		for(VideoTranscoding videoTranscoding:videoTranscodings){
@@ -138,7 +139,8 @@ public class VideoQualityTableFormController extends FormBasicController {
 			} else if (status == VideoTranscoding.TRANSCODING_STATUS_TIMEOUT) {
 				fileSize = translate("transcoding.timeout");
 			} 
-			rows.add(new QualityTableRow(previewVersionLink, dimension,  fileSize, videoTranscoding.getFormat(), deleteLink));
+			Object[] statusTranscoding = new Object[]{status, fileSize};
+			rows.add(new QualityTableRow(previewVersionLink, dimension,statusTranscoding, videoTranscoding.getFormat(), deleteLink));
 		}
 		List<Integer> missingResolutions = videoManager.getMissingTranscodings(videoResource);
 		if (videoModule.isTranscodingEnabled()) {
@@ -151,7 +153,8 @@ public class VideoQualityTableFormController extends FormBasicController {
 					
 					FormLink previewMissingLink= uifactory.addFormLink("res_" + count++, "viewQuality", title, title, flc, Link.LINK + Link.NONTRANSLATED);
 					previewMissingLink.setEnabled(false);
-					rows.add(new QualityTableRow(previewMissingLink, missingRes.toString(),  "-", "mp4", transcodeLink));
+					Object[] status = new Object[]{-1, "-"};
+					rows.add(new QualityTableRow(previewMissingLink, missingRes.toString(),status, "mp4", transcodeLink));
 				}
 			}
 		}
-- 
GitLab