Skip to content

Commit

Permalink
Multiple bug-fixes. VuePanel for panel based on Vue.js
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomYdn committed May 31, 2021
1 parent f93a577 commit af6403e
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 5 deletions.
2 changes: 1 addition & 1 deletion vuecket/src/main/java/org/orienteer/vuecket/DataFiber.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DataFiber(String name, IModel<T> model, IModel<T> initPropModel, boolean
this.name = name;
this.model = model;
this.initPropModel = initPropModel;
this.revisionHash = Objects.hashCode(model!=null?model.getObject():null);
this.revisionHash = -1;
this.init = init || update; //If fiber updatable: it should be also initialized
this.update = update;
this.observe = observe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ public DataFiberBuilder<M, V> update() {
return this;
}


@Deprecated
public V bind() {
return build();
}

public V build() {
DataFiber<M> df = new DataFiber<M>(type, name, model, initPropValue, init, update, observe);
df.bind(locator);
return locator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ public default C setRefreshPeriod(Integer refreshPeriod) {
getVueBehavior().setRefreshPeriod(refreshPeriod);
return getThisComponent();
}

public default DataFibersGroup getDataFibers() {
return getVueBehavior().getDataFibers();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public <M> DataFiberBuilder<M, VueBehavior> dataFiberBuilder(IModel<M> model, St
return new DataFiberBuilder<M, VueBehavior>(this, model, name);
}

DataFibersGroup getDataFibers() {
public DataFibersGroup getDataFibers() {
return dataFibers;
}

Expand Down
39 changes: 39 additions & 0 deletions vuecket/src/main/java/org/orienteer/vuecket/VuePanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.orienteer.vuecket;

import java.util.Map;

import org.apache.wicket.markup.html.GenericWebMarkupContainer;
import org.apache.wicket.markup.html.panel.GenericPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.resource.ResourceReference;
import org.orienteer.vuecket.descriptor.IVueDescriptor;
import org.orienteer.vuecket.descriptor.VueFileDescriptor;
import org.orienteer.vuecket.descriptor.VueJsonDescriptor;
import org.orienteer.vuecket.method.IVuecketMethod;

/**
* Wicket Component with prewired VueBehavior. It's absolutely optional to use this class or not.
* @param <T> the type of the component's model object
*/
public class VuePanel<T> extends GenericPanel<T> implements IVueComponent<VuePanel<T>> {

private final VueBehavior vueBehavior;

public VuePanel(String id) {
this(id, null);
}

public VuePanel(String id, IModel<T> model) {
super(id, model);
add(vueBehavior = new VueBehavior());
}

public VueBehavior getVueBehavior() {
return vueBehavior;
}

@Override
public VuePanel<T> getThisComponent() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.orienteer.vuecket.method;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.wicket.Component;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.util.io.IClusterable;
import org.orienteer.vuecket.DataFiber;
import org.orienteer.vuecket.DataFibersGroup;
import org.orienteer.vuecket.VueBehavior;
import org.orienteer.vuecket.VueSettings;
import org.orienteer.vuecket.util.VuecketUtils;
Expand Down Expand Up @@ -79,4 +85,31 @@ public static void pushPatch(Context ctx, Map<String, ?> dataPatch, Map<String,
throw new WicketRuntimeException(e);
}
}

public static void pushDataFibers(Context ctx, boolean ifChanged, String... dataFiberNames) {
if(dataFiberNames==null || dataFiberNames.length==0) return;
List<DataFiber<?>> dataFibers = new ArrayList<DataFiber<?>>();
DataFibersGroup dataFiberGroup = ctx.getVueBehavior().getDataFibers();
for (String name : dataFiberNames) {
dataFiberGroup.getDataFiberByName(name).ifPresent(dataFibers::add);
}
pushDataFibers(ctx, ifChanged, dataFibers);
}

public static void pushDataFibers(Context ctx, boolean ifChanged, DataFiber<?>... dataFibers) {
if(dataFibers==null || dataFibers.length==0) return;
pushDataFibers(ctx, ifChanged, Arrays.asList(dataFibers));
}

public static void pushDataFibers(Context ctx, boolean ifChanged, Iterable<DataFiber<?>> dataFibers) {
if(dataFibers==null) return;
Map<String, Object> dataPatch = new HashMap<String, Object>();
Map<String, Object> propsPatch = new HashMap<String, Object>();
for (DataFiber<?> df : dataFibers) {
if(!ifChanged || df.isValueChanged()) {
df.updatePatch(dataPatch, propsPatch);
}
}
IVuecketMethod.pushPatch(ctx, dataPatch, propsPatch);
}
}
7 changes: 5 additions & 2 deletions vuecket/src/main/resources/org/orienteer/vuecket/vuecket.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ const Vuecket = {
Object.assign(this.vcConfig.props, propsPatch);

if(this.$parent) this.$parent.$forceUpdate();
else this.$forceUpdate();
else {
Object.assign(this.$props, propsPatch);
this.$forceUpdate();
}
}
}
},
Expand Down Expand Up @@ -109,7 +112,7 @@ const Vuecket = {
}
},
beforeDestroy () {
if(this.vcConfig.refreshTimer) clearInterval(this.vcConfig.refreshTimer);
if(this.vcConfig && this.vcConfig.refreshTimer) clearInterval(this.vcConfig.refreshTimer);
}
});
}
Expand Down

0 comments on commit af6403e

Please sign in to comment.