use of org.olat.modules.portfolio.MediaHandler in project openolat by klemens.
the class MediaUploadController method getHandler.
private MediaHandler getHandler() {
MediaHandler handler = null;
String mimeType = fileEl.getUploadMimeType();
if (StringHelper.containsNonWhitespace(mimeType)) {
List<MediaHandler> availableHandlers = portfolioService.getMediaHandlers();
for (MediaHandler availableHandler : availableHandlers) {
if (availableHandler.acceptMimeType(mimeType)) {
handler = availableHandler;
break;
}
}
}
return handler;
}
use of org.olat.modules.portfolio.MediaHandler in project OpenOLAT by OpenOLAT.
the class MediaCenterController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
if (select) {
newMediaCallout = uifactory.addFormLink("new.medias", formLayout, Link.BUTTON);
newMediaCallout.setIconRightCSS("o_icon o_icon_caret o_icon-fw");
}
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(false, MediaCols.key, "select"));
Map<String, MediaHandler> handlersMap = portfolioService.getMediaHandlers().stream().collect(Collectors.toMap(h -> h.getType(), h -> h));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(MediaCols.type, new MediaTypeCellRenderer(handlersMap)));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(MediaCols.title, "select"));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(MediaCols.collectionDate, "select"));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(MediaCols.categories, new CategoriesCellRenderer()));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("select", translate("select"), "select"));
model = new MediaDataModel(columnsModel, getLocale());
tableEl = uifactory.addTableElement(getWindowControl(), "table", model, 20, false, getTranslator(), formLayout);
tableEl.setAvailableRendererTypes(FlexiTableRendererType.custom, FlexiTableRendererType.classic);
tableEl.setRendererType(FlexiTableRendererType.custom);
tableEl.setSearchEnabled(true);
tableEl.setCustomizeColumns(true);
tableEl.setEmtpyTableMessageKey("table.sEmptyTable");
tableEl.setPageSize(24);
VelocityContainer row = createVelocityContainer("media_row");
// sets its own DOM id in velocity container
row.setDomReplacementWrapperRequired(false);
tableEl.setRowRenderer(row, this);
tableEl.setCssDelegate(new MediaCssDelegate());
tableEl.setAndLoadPersistedPreferences(ureq, "media-list");
initSorters(tableEl);
initFilters(tableEl);
mapperThumbnailUrl = registerCacheableMapper(ureq, "media-thumbnail", new ThumbnailMapper(model));
row.contextPut("mapperThumbnailUrl", mapperThumbnailUrl);
}
use of org.olat.modules.portfolio.MediaHandler in project OpenOLAT by OpenOLAT.
the class MediaCenterController method loadModel.
private void loadModel() {
String searchString = tableEl.getQuickSearchString();
List<String> tagNames = getSelectedTagNames();
Map<Long, MediaRow> currentMap = model.getObjects().stream().collect(Collectors.toMap(r -> r.getKey(), r -> r));
List<MediaLight> medias = portfolioService.searchOwnedMedias(getIdentity(), searchString, tagNames);
List<MediaRow> rows = new ArrayList<>(medias.size());
for (MediaLight media : medias) {
if (currentMap.containsKey(media.getKey())) {
rows.add(currentMap.get(media.getKey()));
} else {
MediaHandler handler = portfolioService.getMediaHandler(media.getType());
VFSLeaf thumbnail = handler.getThumbnail(media, THUMBNAIL_SIZE);
String mediaTitle = StringHelper.escapeHtml(media.getTitle());
FormLink openLink = uifactory.addFormLink("select_" + (++counter), "select", mediaTitle, null, flc, Link.NONTRANSLATED);
MediaRow row = new MediaRow(media, thumbnail, openLink, handler.getIconCssClass(media));
openLink.setUserObject(row);
rows.add(row);
}
}
model.setObjects(rows);
model.filter(tableEl.getSelectedFilters());
Map<Long, MediaRow> rowMap = model.getObjects().stream().collect(Collectors.toMap(r -> r.getKey(), r -> r));
Set<String> duplicateCategories = new HashSet<>();
List<CategoryLight> categories = portfolioService.getMediaCategories(getIdentity());
List<FormLink> newTagLinks = new ArrayList<>(categories.size());
for (CategoryLight category : categories) {
String name = category.getCategory();
MediaRow mRow = rowMap.get(category.getMediaKey());
if (mRow != null) {
mRow.addCategory(name);
}
if (duplicateCategories.contains(name)) {
continue;
}
duplicateCategories.add(name);
FormLink tagLink = uifactory.addFormLink("tag_" + (++counter), "tag", name, null, null, Link.NONTRANSLATED);
CategoryState state = new CategoryState(category, tagNames.contains(name));
tagLink.setUserObject(state);
if (state.isSelected()) {
tagLink.setCustomEnabledLinkCSS("tag label label-info o_disabled");
} else {
tagLink.setCustomEnabledLinkCSS("tag label label-info");
}
flc.add(tagLink);
newTagLinks.add(tagLink);
}
flc.contextPut("tagLinks", newTagLinks);
tagLinks = newTagLinks;
}
use of org.olat.modules.portfolio.MediaHandler in project OpenOLAT by OpenOLAT.
the class MediaUploadController method getHandler.
private MediaHandler getHandler() {
MediaHandler handler = null;
String mimeType = fileEl.getUploadMimeType();
if (StringHelper.containsNonWhitespace(mimeType)) {
List<MediaHandler> availableHandlers = portfolioService.getMediaHandlers();
for (MediaHandler availableHandler : availableHandlers) {
if (availableHandler.acceptMimeType(mimeType)) {
handler = availableHandler;
break;
}
}
}
return handler;
}
use of org.olat.modules.portfolio.MediaHandler in project OpenOLAT by OpenOLAT.
the class MediaUploadController method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (mediaReference == null) {
String title = titleEl.getValue();
String description = descriptionEl.getValue();
File uploadedFile = fileEl.getUploadFile();
String uploadedFilename = fileEl.getUploadFileName();
MediaHandler mediaHandler = getHandler();
if (mediaHandler != null) {
UploadMedia mObject = new UploadMedia(uploadedFile, uploadedFilename, fileEl.getUploadMimeType());
mediaReference = mediaHandler.createMedia(title, description, mObject, businessPath, getIdentity());
}
} else {
// TODO can we update an artefact?
}
List<String> updatedCategories = categoriesEl.getValueList();
portfolioService.updateCategories(mediaReference, updatedCategories);
fireEvent(ureq, Event.DONE_EVENT);
}
Aggregations