Skip to content

Commit

Permalink
util.assertInstanceOf: simplified call, Icon: reformatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrode committed Feb 22, 2021
1 parent 15b604c commit 9f17c3e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 73 deletions.
4 changes: 2 additions & 2 deletions src/base/Element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class CUI.Element
if CUI.util.isArray(v.check)
CUI.util.assert(v.check.indexOf(value) > -1, cls, "opts.#{k} needs to be one of [\"#{v.check.join('\",\"')}\"].", opts: opts)
else if v.check == Boolean or v.check == String or v.check == Function or v.check == Array
CUI.util.assertInstanceOf.call(@, k, v.check, undefined, value)
CUI.util.assertInstanceOf.call(@, k, v.check, value)
else if CUI.util.isFunction(v.check) and not v.check.__super__ # super is from coffeescript and shows us that we have a "class" here
CUI.util.assert(CUI.util.isEmpty(v.check.name) or v.check.name == "check", cls, "#{k}.check is \"#{v.check.name}\" but has no \"__super__\" method. Use \"extends CUI.Element\" or \"extends CUI.Dummy\" to fix that.", opts: opts, key: k, value: v)
check = v.check.call(@, value)
Expand All @@ -234,7 +234,7 @@ class CUI.Element
else if CUI.util.isNull(value) and mandatory
CUI.util.assert(false, cls, "opts.#{k} is mandatory, but is #{value}.", opts: opts)
else
CUI.util.assertInstanceOf.call(@, k, v.check, undefined, value)
CUI.util.assertInstanceOf.call(@, k, v.check, value)

# convenient mapping this to our space
if map_values
Expand Down
135 changes: 70 additions & 65 deletions src/base/Icon/Icon.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ class CUI.Icon extends CUI.Element
svg_cls = ""
cls = ""
if @_icon
cls = CUI.Icon.icon_map[@_icon]
if CUI.util.isEmpty(cls)
# common map icon
if not cls
cls = CUI.Icon.icon_map[@_icon]

# fallback to value of icon
if not cls
cls = @_icon

if cls.startsWith("svg-")
Expand Down Expand Up @@ -56,85 +60,86 @@ class CUI.Icon extends CUI.Element
CUI.dom.showElement(@DOM)

@icon_map:
trash: "svg-trash"
reset: "svg-reset"
spinner: "svg-spinner cui-spin-stepped"
remove: "svg-close"
audio: "fa-music"
bolt: "fa-bolt"
calendar: "fa-calendar-plus-o"
camera: "fa-camera"
check: "fa-check"
clock: "fa-clock-o"
close: "svg-close"
folder: "svg-folder"
folder_shared: "svg-folder-shared"
folder_upload: "svg-folder-upload"
folder_shared_upload: "svg-folder-shared-upload"
info_circle: "svg-info-circle"
external_link: "svg-external-link"
cloud: "fa-cloud"
copy: "fa-files-o"
crop: "fa-crop"
fullscreen: "fa-arrows-alt"
dive: "fa-angle-right"
down: "fa-caret-down"
download: "fa-download"
east: "fa-angle-right"
edit: "fa-pencil"
ellipsis_h: "fa-ellipsis-h"
ellipsis_v: "fa-ellipsis-v" #used for sidemenu buttons
email: "fa-envelope-o"
envelope_active: "fa-envelope"
envelope: "fa-envelope-o"
expert_search: "fa-list-ul" #"fa-binoculars" #"fa-mortar-board"
export: "fa-download"
external_link: "svg-external-link"
failed: "fa-warning"
no_right: "fa-slack"
file_text : "fa-file-text-o"
file_text_active : "fa-file-text"
file: "fa-file"
filter: "fa-filter"
sliders: "fa-sliders"
folder_shared_upload: "svg-folder-shared-upload"
folder_shared: "svg-folder-shared"
folder_upload: "svg-folder-upload"
folder: "svg-folder"
fullscreen: "fa-arrows-alt"
heart: "fa-heart"
help: "fa-question"
image: "fa-picture-o"
info_circle: "svg-info-circle"
info_circle_ng: "svg-info-circle-ng"
info: "fa-info-circle"
left: "fa-angle-left"
legal: "fa-legal"
list: "fa-question"
menu: "fa-bars"
minus: "fa-minus"
no_right: "fa-slack"
north: "fa-angle-up"
play: "fa-play"
plus: "fa-plus"
print: "fa-print"
question: "fa-question"
refresh: "fa-refresh"
zip: "fa fa-file-archive-o"
rotate_right: "fa-rotate-right"
remove: "svg-close"
required: "fa-bullhorn"
reset: "svg-reset"
resize_full: "fa-expand"
resize_small: "fa-compress"
right: "fa-angle-right"
rotate_horizontal: "fa-arrows-h"
rotate_left: "fa-rotate-left"
rotate_right: "fa-rotate-right"
rotate_vertical: "fa-arrows-v"
rotate_horizontal: "fa-arrows-h"
calendar: "fa-calendar-plus-o"
show: "fa-question"
help: "fa-question"
question: "fa-question"
settings: "fa-cog"
download: "fa-download"
export: "fa-download"
list: "fa-question"
upload: "fa-upload"
envelope: "fa-envelope-o"
envelope_active: "fa-envelope"
save: "fa-floppy-o"
heart: "fa-heart"
user: "fa-user"
clock: "fa-clock-o"
plus: "fa-plus"
edit: "fa-pencil"
copy: "fa-files-o"
search: "fa-search"
settings: "fa-cog"
share: "fa-share"
play: "fa-play"
audio: "fa-music"
show: "fa-question"
sliders: "fa-sliders"
south: "fa-angle-down"
spinner: "svg-spinner cui-spin-stepped"
start: "fa-play"
stop: "fa-stop"
print: "fa-print"
minus: "fa-minus"
ellipsis_h: "fa-ellipsis-h"
ellipsis_v: "fa-ellipsis-v" #used for sidemenu buttons
menu: "fa-bars"
info: "fa-info-circle"
bolt: "fa-bolt"
check: "fa-check"
trash: "svg-trash"
up: "fa-caret-up"
upload: "fa-upload"
user: "fa-user"
warning: "fa-warning"
legal: "fa-legal"
cloud: "fa-cloud"
left: "fa-angle-left"
right: "fa-angle-right"
dive: "fa-angle-right"
west: "fa-angle-left"
zip: "fa fa-file-archive-o"
zoom_in: "fa-search-plus"
zoom_out: "fa-search-minus"
resize_small: "fa-compress"
resize_full: "fa-expand"
email: "fa-envelope-o"
file_text_active : "fa-file-text"
file_text : "fa-file-text-o"
required: "fa-bullhorn"
west: "fa-angle-left"
east: "fa-angle-right"
south: "fa-angle-down"
north: "fa-angle-up"
up: "fa-caret-up"
down: "fa-caret-down"
camera: "fa-camera"
expert_search: "fa-list-ul" #"fa-binoculars" #"fa-mortar-board"
image: "fa-picture-o"


CUI.proxyMethods(CUI.Icon, CUI.Button, ["hide", "show", "isShown","isHidden"])
Expand Down
8 changes: 2 additions & 6 deletions src/base/util.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,13 @@ class CUI.util
CUI.util.assert(needs.length == 0, "#{CUI.util.getObjectClass(inst)}", "Needs implementations for #{needs.join(', ')}.", instance: inst)
return

@assertInstanceOf: (variableName, classClass, opts, value=undefined) ->
@assertInstanceOf: (variableName, classClass, value) ->
if not CUI.defaults.asserts
return

if not CUI.util.isFunction(classClass) and not classClass == "PlainObject"
throw "assertInstanceOf: class is not a Function"

if value == undefined
value = opts[variableName]
CUI.util.assert(CUI.util.isPlainObject(opts), "new #{arguments.callee.caller.name}", "opts needs to be PlainObject but it is #{CUI.util.getObjectClass(opts)}.", opts: opts)

if classClass == "Array"
cn = "Array"
cond = value instanceof Array
Expand All @@ -121,7 +117,7 @@ class CUI.util
if not fn
fn = CUI.util.getObjectClass(@)

CUI.util.assert(false, "new #{fn}", "opts.#{variableName} needs to be instance of #{cn} but it is #{CUI.util.getObjectClass(value)}.", opts: opts, value: value, classClass: classClass)
CUI.util.assert(false, "new #{fn}", "opts.#{variableName} needs to be instance of #{cn} but it is #{CUI.util.getObjectClass(value)}.", value: value, classClass: classClass)
return

@$elementIsInDOM: ($el) ->
Expand Down

0 comments on commit 9f17c3e

Please sign in to comment.