Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
reginaldo.marinho committed Jan 22, 2025
1 parent 8c2a7e2 commit 9125ae7
Show file tree
Hide file tree
Showing 9 changed files with 595 additions and 337 deletions.
514 changes: 317 additions & 197 deletions public/style.css

Large diffs are not rendered by default.

139 changes: 108 additions & 31 deletions src/Rucula.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { window } from "./entities/form/window";
import { WindowBaseDOM } from "./elements/window-base/WindowBase";
import { constIdBaseWindow, constTypeFrame } from "./const";
import { constIdBaseWindow, constTypeFrame, eventRucula } from "./const";
import { EventButton } from "./buttons/EventButton";
import { configWindow } from "./window/Window";
import { defaultValues } from "./elements/Defaults";
import { LayoutFrame } from "./Layout/layout";
import { ButtonsBase } from "./buttons/buttonsBaseCrud";
import { DOMButtonsCheck } from "./buttons/buttonsBaseCrud";
import { ruculaGlobal } from "./global/GlobalConfig";
import { LoaderManagment } from "./elements/loader/loader";
import { Popup } from "./popup/popup";
Expand All @@ -28,13 +28,14 @@ import { buttonURL } from "./entities/form/button";
import { WindowAPI } from "./window/windowAPI";
import { ButtonManaged } from "./elements/window-base/buttonManaged";
import { globalConfiguration } from "./entities/global/GlobalConfiguration";
import { frame } from "./entities/form/frame";

export class Rucula{

private P = `ruculajs_${Date.now()}`
private windowBaseDOM!:WindowBaseDOM
private window!: window
private globalWindow!: HTMLElement
public globalWindow!: HTMLElement
private elementFormRucula!: HTMLFormElement
private menuContext!:MenuContext
public popup!:Popup
Expand All @@ -50,23 +51,25 @@ export class Rucula{
private config:any
private fieldMenuContext!:FieldMenuContext
private paginationEvents!:PaginationEvents
private buttonsBase!:ButtonsBase
private domButtomCheck!:DOMButtonsCheck
private frameBlock!:FrameElementBlock
private frameLine!:FrameElementLine
public loader!:LoaderManagment
public buttonManaged!:ButtonManaged

private perspective?: Perspective

constructor(config: {
global:globalConfiguration,
urlWindow?:buttonURL,
window?:window,
window?:window,
perspective?: Perspective
id?:string,
reload?:() => void
}){

this.perspective = config.perspective
config.id ??= 'rucula-js';
this.config = config

ruculaGlobal.initGlobalConfiguration(config.global)
}

Expand All @@ -82,6 +85,8 @@ export class Rucula{
this.window = this.config.window
}

this.configurePerspective()

this.globalWindow = document.getElementById(this.config.id!)!

this.popup = new Popup(this.P)
Expand All @@ -93,7 +98,7 @@ export class Rucula{
this.paginationEvents = new PaginationEvents(this.P, this.globalWindow)


this.buttonsBase = new ButtonsBase(this.P)
this.domButtomCheck = new DOMButtonsCheck(this.P,this.window?.crud)
this.loader = new LoaderManagment(this.P)
this.button = new Button(() => {
let rucula = new Rucula(this.config)
Expand All @@ -104,11 +109,12 @@ export class Rucula{

defaultValues.setDefault(this.window)


this.windowBaseDOM = new WindowBaseDOM(this.P, {
globalWindow:this.globalWindow,
openLeftGrid: this.window?.grid ?? false,
windowName: this.window?.name
windowName: this.window?.name,
type:this.window.type
})

if(this.window == null){
Expand All @@ -130,9 +136,7 @@ export class Rucula{
}

create(){

this.cleanRucula();


let eventInit = new Event('rucula.init')
let eventLoad = new Event('rucula.load')

Expand All @@ -151,23 +155,28 @@ export class Rucula{
let form = this.globalWindow.querySelector('form.r-window-work')

form?.addEventListener('change',() => {
this.buttonManaged.initTosave()
}
)
this.buttonManaged.initTosave()
})

this.paginationEvents.headerSearch(this.window.gridSearch);
this.paginationEvents.fotter(this.window.gridFooter)
this.layoutFrame.configureLayout(this.window,this.elementFormRucula)

this.createButtons()
this.createFrames()
this.buttonsBase.initButtonsTypeCrudDefault()
this.buttonsBase.initButtonPlus()
this.buttonsBase.crud(this.window?.crud)

if(this.window.type != 'header'){
this.domButtomCheck.removeUnusedButtons()
}

if(this.window.type == 'crud'){
this.layoutFrame.configureLayout(this.window,this.elementFormRucula)
this.createFrames()
}


this.globalWindow.dispatchEvent(eventLoad);

(window as any).rucula = new RuculaLogs(this.managmentObject)


this.tableDependency.snapshot()
this.fragment.snapshot()

Expand Down Expand Up @@ -201,19 +210,13 @@ export class Rucula{
callback()
}

private cleanRucula(){
for (let index = 0; index < this.globalWindow.childNodes.length; index++) {
this.globalWindow.childNodes[index].remove();
}
}

private createButtons(type:string="CRUD"){

if(type == "CRUD"){
this.button.prepareButtonsInLeftBox(this.window.button)
}
this.eventButton.eventButton(this.globalWindow, this.window.pathController, this.window.button)
this.eventButton.openCloseRightListButtons()
this.eventButton.openCloseRightListButtonsActions()
}

private createFrames(){
Expand Down Expand Up @@ -269,6 +272,9 @@ export class Rucula{
return this.managmentObject.objectSeparate()
}

private eventRuculaChange = new Event('ruculaChange')
private eventFocusOut = new Event('focusout')

setValue (targetPath:string, value: any) {

const ATTR_DISABLED = 'disabled'
Expand All @@ -281,9 +287,19 @@ export class Rucula{
if(disabled){
input.removeAttribute(ATTR_DISABLED)
}
input.value = value
let onChange = input.value != value && input.getAttribute('type') === 'checkbox'

input.focus({preventScroll: true}) //! This command forces the objectmanagment and tableDependecy processes to run
input.blur()

input.value = value

if(onChange){
input.dispatchEvent(this.eventRuculaChange)
}


input.dispatchEvent(this.eventFocusOut)


if(disabled){
input.setAttribute(ATTR_DISABLED,'')
Expand All @@ -305,4 +321,65 @@ export class Rucula{
this.frameBlock.revertToInit();
this.frameLine.revertToInit();
}

private configurePerspective(){

if(this.perspective == null){
return
}

for (let index = 0; index < this.perspective?.frame.length; index++) {

var frameAlias = this.perspective?.frame[index]

var frame = this.window.frames.find(c=> c.alias == frameAlias)

if(frame == null){
continue
}

let indexof = this.window.frames.indexOf(frame)

this.window.frames.splice(indexof,1)
}

this.perspective?.field.sort();

let lastFrame:frame|undefined
for (let index = 0; index < this.perspective?.field.length; index++) {

let field = this.perspective?.field[index].split('.')

if(lastFrame?.alias != field[0]) {
let frame = this.window.frames.find(c=> c.alias == field[0])

if(frame == null){
continue
}

lastFrame = frame
}

remove(lastFrame!, field[1])

}

function remove(frame:frame, propert:string){

var field = frame.fields?.find(c=> c.propertDto == propert)

if(field == null){
return
}

let indexof = frame.fields?.indexOf(field)

frame.fields?.splice(indexof!,1)
}
}
}

export type Perspective = {
frame:string[],
field:string[]
}
4 changes: 2 additions & 2 deletions src/buttons/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ export class Button {

prepareButtonsInLeftBox (button:button[]) {

const ListRightButtons = document.getElementById(`${this.P}r-a-menu-vertical-list`)
const ListRightButtons = document.getElementById(`${this.P}${constIdBaseWindow.BUTTONS_MENU_VERTICAL_LIST}`)

let buttons = button?.filter(c=> this.buttonIsNotDefault(c.target))

if(buttons?.length == 0 || buttons == undefined){
Expand Down
22 changes: 14 additions & 8 deletions src/buttons/EventButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,25 @@ export class EventButton {
});
}

openCloseRightListButtons(){
openCloseRightListButtonsActions(){

const openClose = document.getElementById(`${this.P}r-a-menu-vertical`) as HTMLElement
const listRight = document.querySelector(`.${this.P}r-vertical-actions`) as HTMLElement
const buttonOpenClose = document.getElementById(`${this.P}r-a-menu-vertical`) as HTMLElement
const buttonMobileClose = document.getElementById(`${this.P}${constIdBaseWindow.BUTTON_MENU_VERTICAL_MOBILE_CLOSE}`)
const buttonOpenClosemobile = document.getElementById(`${this.P}${constIdBaseWindow.BUTTONS_MENU_VERTICAL_MOBILE}`)

const openClosemobile = document.getElementById(`${this.P}${constIdBaseWindow.BUTTONS_MENU_VERTICAL_MOBILE}`)
const divRightListButtonsActions = document.querySelector(`.r-vertical-actions`) as HTMLElement

openClose?.addEventListener("click",() => {
listRight?.classList.toggle("r-display-none");
buttonOpenClose?.addEventListener("click",() => {
divRightListButtonsActions?.classList.toggle("r-display-none");

})

openClosemobile?.addEventListener("click",() => {
listRight?.classList.toggle("r-display-none");
buttonOpenClosemobile?.addEventListener("click",() => {
divRightListButtonsActions?.classList.toggle("r-display-block");
})

buttonMobileClose?.addEventListener("click",() => {
divRightListButtonsActions?.classList.toggle("r-display-block");
})
}
}
34 changes: 19 additions & 15 deletions src/buttons/buttonsBaseCrud.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { constIdBaseWindow, constTargetButtonCrudDefault } from "../const"

export class ButtonsBase {
export class DOMButtonsCheck {

buttonCreate!:HTMLButtonElement
buttonAlter!:HTMLButtonElement
buttonDelete!:HTMLButtonElement
private buttonCreate!:HTMLButtonElement
private buttonAlter!:HTMLButtonElement
private buttonDelete!:HTMLButtonElement

buttonsPlus!:HTMLButtonElement
olButtonsPlus!:HTMLOListElement
private buttonsPlus!:HTMLButtonElement
private olButtonsPlus!:HTMLOListElement

P:string
constructor(P:string) {
private P:string
private crud:string
constructor(P:string,crud:string) {
this.P = P

this.crud = crud
}
initButtonsTypeCrudDefault(){
private buttonCrudDefault(){
this.buttonCreate = document.getElementById(`${this.P}${constTargetButtonCrudDefault.SAVE}`) as HTMLButtonElement
this.buttonAlter = document.getElementById(`${this.P}${constTargetButtonCrudDefault.ALTER}`) as HTMLButtonElement
this.buttonDelete = document.getElementById(`${this.P}${constTargetButtonCrudDefault.DELETE}`) as HTMLButtonElement
}

initButtonPlus(){
private SpecificRightButtons (){
this.buttonsPlus = document.getElementById(`${this.P}${constIdBaseWindow.BUTTONS_MENU_VERTICAL}`) as HTMLButtonElement
this.olButtonsPlus = document.getElementById(`${this.P}${constIdBaseWindow.BUTTONS_MENU_VERTICAL_LIST}`) as HTMLOListElement

Expand Down Expand Up @@ -54,9 +55,12 @@ export class ButtonsBase {
this.buttonDelete.remove()
}

crud (crud:string) {
removeUnusedButtons () {

if(crud == "" || crud == undefined){
this.buttonCrudDefault();
this.SpecificRightButtons();

if(this.crud == "" || this.crud == undefined){
this.buttonCreate.remove()
this.buttonAlter.remove()
this.buttonDelete.remove()
Expand All @@ -65,9 +69,9 @@ export class ButtonsBase {

let options = "crud";

for (let index = 0; index < crud.length; index++) {
for (let index = 0; index < this.crud.length; index++) {

let indexof = options.indexOf(crud[index])
let indexof = options.indexOf(this.crud[index])

options = options.replace(options[indexof],"")
}
Expand Down
3 changes: 3 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ export const constTypeFrame = {
export const constIdBaseWindow = {

NEW: "r-a-new",
CLOSE_GRID:"close-grid",
RELOAD:"r-a-reload",
ERASE_WINDOW: "erase-window",
ALTER_THEME: "alter-theme",
MAXIMIZE_WINDOW: "maximize-window",
MAXIMIZE_GRID: "maximize-grid",
ACTIONS_WINDOW: "r-actiond-window",
GLOBALIZATION: "r-globalization",
OLLI_GLOBALIZATION: "r-globalization-list",
Expand All @@ -68,6 +70,7 @@ export const constIdBaseWindow = {
FORM_RUCULA_JS:"form-rucula-js",
BUTTONS_MENU_VERTICAL: "r-a-menu-vertical",
BUTTONS_MENU_VERTICAL_MOBILE: "r-a-menu-vertical-mobile",
BUTTON_MENU_VERTICAL_MOBILE_CLOSE: "r-a-mobile-close",
BUTTONS_MENU_VERTICAL_LIST: "r-a-menu-vertical-list",
TITLE:"r-window-title",
FAVORITE:"r-favorite",
Expand Down
Loading

0 comments on commit 9125ae7

Please sign in to comment.