-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
completed styling updates and added new component and helpers
- Loading branch information
Showing
12 changed files
with
235 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<div class="x-fleetbase-file" ...attributes> | ||
<div class="x-fleetbase-file-wrapper"> | ||
<div class="x-fleetbase-file-actions"> | ||
<DropdownButton @dropdownId="x-fleetbase-file-actions-dropdown" @icon="ellipsis" @iconSize="xs" @iconPrefix={{@dropdownButtonIconPrefix}} @text={{@dropdownButtonText}} @size="xs" @horizontalPosition="left" @calculatePosition={{@dropdownButtonCalculatePosition}} @renderInPlace={{or @dropdownButtonRenderInPlace true}} @wrapperClass={{concat @dropdownButtonWrapperClass " " "next-nav-item-dropdown-button"}} @triggerClass={{@dropdownButtonTriggerClass}} @registerAPI={{@registerAPI}} @onInsert={{this.onDropdownButtonInsert}} as |dd|> | ||
<div class="next-dd-menu mt-0i" role="menu" aria-orientation="vertical" aria-labelledby="user-menu"> | ||
<div class="px-1"> | ||
<div class="text-sm flex flex-row items-center px-3 py-1 rounded-md my-1 text-gray-800 dark:text-gray-300"> | ||
{{t "component.file.dropdown-label"}} | ||
</div> | ||
</div> | ||
<div class="next-dd-menu-seperator"></div> | ||
<div role="group" class="px-1"> | ||
{{!-- template-lint-disable no-nested-interactive --}} | ||
<a href="javascript:;" role="menuitem" class="next-dd-item text-danger" {{on "click" (fn this.onDropdownItemClick "onDelete" dd)}}> | ||
<span class="mr-1"> | ||
<FaIcon @icon="trash" @prefix={{@dropdownButtonIconPrefix}} /> | ||
</span> | ||
{{t "common.delete"}} | ||
</a> | ||
</div> | ||
</div> | ||
</DropdownButton> | ||
</div> | ||
<div class="flex flex-1 flex-col justify-between items-center"> | ||
<div class="flex-1"> | ||
{{#if this.isImage}} | ||
<Image src={{@file.url}} alt={{@file.original_filename}} class="x-fleetbase-file-preview rounded-md shadow-sm" /> | ||
{{else}} | ||
<div class="x-fleetbase-file-preview"> | ||
<FileIcon @file={{@file}} @hideExtension={{true}} @iconSize="2xl" /> | ||
</div> | ||
{{/if}} | ||
</div> | ||
<div class="flex-1 overflow-hidden flex flex-col items-center justify-end"> | ||
<div class="x-fleetbase-file-name"> | ||
{{truncate-filename @file.original_filename}} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
|
||
export default class FileComponent extends Component { | ||
@tracked file; | ||
@tracked isImage = false; | ||
|
||
constructor(owner, { file }) { | ||
super(...arguments); | ||
|
||
this.file = file; | ||
this.isImage = this.isImageFile(file); | ||
} | ||
|
||
@action onDropdownItemClick(action, dd) { | ||
if (typeof dd.actions === 'object' && typeof dd.actions.close === 'function') { | ||
dd.actions.close(); | ||
} | ||
|
||
if (typeof this.args[action] === 'function') { | ||
this.args[action](this.file); | ||
} | ||
} | ||
|
||
isImageFile(file) { | ||
if (!file || (!file.original_filename && !file.url && !file.path)) { | ||
return false; | ||
} | ||
|
||
const filename = file.original_filename || file.url || file.path; | ||
const extensionMatch = filename.match(/\.(.+)$/); | ||
|
||
if (!extensionMatch) { | ||
return false; | ||
} | ||
|
||
const extension = extensionMatch[1].toLowerCase(); | ||
const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'webp']; | ||
|
||
return imageExtensions.includes(extension); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { helper } from '@ember/component/helper'; | ||
|
||
export default helper(function truncateFilename([filename, maxLength = 20]) { | ||
if (!filename || typeof filename !== 'string' || filename.length <= maxLength) { | ||
return filename; | ||
} | ||
|
||
const extensionMatch = filename.match(/\.(.+)$/); | ||
const extension = extensionMatch ? extensionMatch[0] : ''; | ||
const baseName = filename.slice(0, -extension.length); | ||
|
||
if (maxLength <= extension.length) { | ||
// If the maximum length is less than or equal to the extension's length, return only the extension | ||
return `...${extension}`; | ||
} | ||
|
||
const truncated = baseName.slice(0, maxLength - extension.length - 3) + '...'; | ||
|
||
return truncated + extension; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '@fleetbase/ember-ui/components/file'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '@fleetbase/ember-ui/helpers/truncate-filename'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'dummy/tests/helpers'; | ||
import { render } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
|
||
module('Integration | Component | file', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('it renders', async function (assert) { | ||
// Set any properties with this.set('myProperty', 'value'); | ||
// Handle any actions with this.set('myAction', function(val) { ... }); | ||
|
||
await render(hbs`<File />`); | ||
|
||
assert.dom().hasText(''); | ||
|
||
// Template block usage: | ||
await render(hbs` | ||
<File> | ||
template block text | ||
</File> | ||
`); | ||
|
||
assert.dom().hasText('template block text'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'dummy/tests/helpers'; | ||
import { render } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
|
||
module('Integration | Helper | truncate-filename', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
// TODO: Replace this with your real tests. | ||
test('it renders', async function (assert) { | ||
this.set('inputValue', '1234'); | ||
|
||
await render(hbs`{{truncate-filename this.inputValue}}`); | ||
|
||
assert.dom().hasText('1234'); | ||
}); | ||
}); |