mirror of https://github.com/Squidex/squidex.git
17 changed files with 353 additions and 40 deletions
@ -0,0 +1,44 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Microsoft.AspNetCore.Mvc.Filters; |
|||
using Microsoft.AspNetCore.Mvc.Internal; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Squidex.Domain.Apps.Entities.Assets; |
|||
|
|||
namespace Squidex.Pipeline |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] |
|||
public sealed class AssetRequestSizeLimitAttribute : Attribute, IFilterFactory, IOrderedFilter |
|||
{ |
|||
public int Order { get; set; } = 900; |
|||
|
|||
public bool IsReusable => true; |
|||
|
|||
public IFilterMetadata CreateInstance(IServiceProvider serviceProvider) |
|||
{ |
|||
var assetOptions = serviceProvider.GetService<IOptions<AssetOptions>>(); |
|||
|
|||
if (assetOptions?.Value.MaxSize > 0) |
|||
{ |
|||
var filter = serviceProvider.GetRequiredService<RequestSizeLimitFilter>(); |
|||
|
|||
filter.Bytes = assetOptions.Value.MaxSize; |
|||
|
|||
return filter; |
|||
} |
|||
else |
|||
{ |
|||
var filter = serviceProvider.GetRequiredService<DisableRequestSizeLimitFilter>(); |
|||
|
|||
return filter; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
<input class="form-control" type="text" #input |
|||
[style.background]="snapshot.value" |
|||
[style.color]="snapshot.foreground" |
|||
[placeholder]="placeholder" |
|||
[ngModel]="snapshot.value" |
|||
(ngModelChange)="writeValue($event)" |
|||
(focus)="modal.show()" (blur)="blur()" /> |
|||
|
|||
<div *sqxModalView="modal" [sqxModalTarget]="input" position="bottom-left"> |
|||
<div [style.background]="snapshot.value" |
|||
[cpToggle]="true" |
|||
[cpDialogDisplay]="'inline'" |
|||
[cpCancelButton]="false" |
|||
[colorPicker]="snapshot.value" |
|||
(colorPickerChange)="writeValue($event)"> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,18 @@ |
|||
@import '_mixins'; |
|||
@import '_vars'; |
|||
|
|||
:host /deep/ { |
|||
.color-picker { |
|||
& { |
|||
border-color: $color-border; |
|||
} |
|||
|
|||
.hex-text { |
|||
.box { |
|||
input { |
|||
border-color: $color-input; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, forwardRef, Input } from '@angular/core'; |
|||
import { NG_VALUE_ACCESSOR } from '@angular/forms'; |
|||
|
|||
import { |
|||
MathHelper, |
|||
ModalModel, |
|||
StatefulControlComponent |
|||
} from '@app/framework/internal'; |
|||
|
|||
export const SQX_COLOR_PICKER_CONTROL_VALUE_ACCESSOR: any = { |
|||
provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => ColorPickerComponent), multi: true |
|||
}; |
|||
|
|||
interface State { |
|||
value?: string; |
|||
|
|||
foreground: string; |
|||
} |
|||
|
|||
@Component({ |
|||
selector: 'sqx-color-picker', |
|||
styleUrls: ['./color-picker.component.scss'], |
|||
templateUrl: './color-picker.component.html', |
|||
providers: [SQX_COLOR_PICKER_CONTROL_VALUE_ACCESSOR], |
|||
changeDetection: ChangeDetectionStrategy.OnPush |
|||
}) |
|||
export class ColorPickerComponent extends StatefulControlComponent<State, string> { |
|||
@Input() |
|||
public placeholder = ''; |
|||
|
|||
public modal = new ModalModel(); |
|||
|
|||
constructor(changeDetector: ChangeDetectorRef) { |
|||
super(changeDetector, { foreground: 'black' }); |
|||
} |
|||
|
|||
public writeValue(obj: any) { |
|||
let foreground = 'black'; |
|||
|
|||
if (MathHelper.toLuminance(MathHelper.parseColor(obj)!) < .5) { |
|||
foreground = 'white'; |
|||
} |
|||
|
|||
this.next(s => ({ ...s, value: obj, foreground })); |
|||
|
|||
this.callChange(obj); |
|||
} |
|||
|
|||
public blur() { |
|||
this.callTouched(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue