Przeglądaj źródła

add icons using DOM manipulation instead of appending to innerHtml

pull/43/head
Jonathan Cobb 4 lat temu
rodzic
commit
90b3d4dee7
10 zmienionych plików z 50 dodań i 18 usunięć
  1. +1
    -1
      bubble-server/src/main/java/bubble/app/bblock/BubbleBlockAppConfigDriver.java
  2. +2
    -2
      bubble-server/src/main/java/bubble/model/app/AppRule.java
  3. +14
    -4
      bubble-server/src/main/java/bubble/rule/AbstractAppRuleDriver.java
  4. +2
    -1
      bubble-server/src/main/java/bubble/rule/AppRuleDriver.java
  5. +3
    -1
      bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockRuleDriver.java
  6. +1
    -1
      bubble-server/src/main/java/bubble/service/stream/StandardAppPrimerService.java
  7. +10
    -2
      bubble-server/src/main/java/bubble/service/stream/StandardRuleEngineService.java
  8. +10
    -3
      bubble-server/src/main/resources/bubble/rule/RequestModifierRule_icon.js.hbs
  9. +4
    -2
      bubble-server/src/main/resources/bubble/rule/bblock/BubbleBlockRuleDriver_stats.js.hbs
  10. +3
    -1
      bubble-server/src/main/resources/bubble/rule/social/block/JsUserBlockerRuleDriver.js.hbs

+ 1
- 1
bubble-server/src/main/java/bubble/app/bblock/BubbleBlockAppConfigDriver.java Wyświetl plik

@@ -190,7 +190,7 @@ public class BubbleBlockAppConfigDriver extends AppConfigDriverBase {
try {
final AppRule rule = loadRule(account, app);
final RuleDriver ruleDriver = loadDriver(account, rule, BubbleBlockRuleDriver.class);
final BubbleBlockRuleDriver unwiredDriver = (BubbleBlockRuleDriver) rule.initDriver(ruleDriver, TEST_MATCHER, account, TEST_DEVICE);
final BubbleBlockRuleDriver unwiredDriver = (BubbleBlockRuleDriver) rule.initDriver(app, ruleDriver, TEST_MATCHER, account, TEST_DEVICE);
final BubbleBlockRuleDriver driver = configuration.autowire(unwiredDriver);
final BlockDecision decision = driver.getDecision(host, path, userAgent, primary);
return getBuiltinList(account, app).setResponse(decision);


+ 2
- 2
bubble-server/src/main/java/bubble/model/app/AppRule.java Wyświetl plik

@@ -90,9 +90,9 @@ public class AppRule extends IdentifiableBaseParentEntity implements AppTemplate
@Column(nullable=false, length=UUID_MAXLEN)
@Getter @Setter private String driver;

public AppRuleDriver initDriver(RuleDriver driver, AppMatcher matcher, Account account, Device device) {
public AppRuleDriver initDriver(BubbleApp app, RuleDriver driver, AppMatcher matcher, Account account, Device device) {
final AppRuleDriver d = driver.getDriver();
d.init(json(configJson, JsonNode.class), driver.getUserConfig(), this, matcher, account, device);
d.init(json(configJson, JsonNode.class), driver.getUserConfig(), app, this, matcher, account, device);
return d;
}



+ 14
- 4
bubble-server/src/main/java/bubble/rule/AbstractAppRuleDriver.java Wyświetl plik

@@ -11,6 +11,7 @@ import bubble.dao.device.DeviceDAO;
import bubble.model.account.Account;
import bubble.model.app.AppMatcher;
import bubble.model.app.AppRule;
import bubble.model.app.BubbleApp;
import bubble.model.device.Device;
import bubble.resources.stream.FilterHttpRequest;
import bubble.server.BubbleConfiguration;
@@ -60,6 +61,7 @@ public abstract class AbstractAppRuleDriver implements AppRuleDriver {

protected JsonNode config;
protected JsonNode userConfig;
protected BubbleApp app;
protected AppMatcher matcher;
protected AppRule rule;
protected Account account;
@@ -76,12 +78,14 @@ public abstract class AbstractAppRuleDriver implements AppRuleDriver {

@Override public void init(JsonNode config,
JsonNode userConfig,
BubbleApp app,
AppRule rule,
AppMatcher matcher,
Account account,
Device device) {
this.config = config;
this.userConfig = userConfig;
this.app = app;
this.matcher = matcher;
this.rule = rule;
this.account = account;
@@ -175,22 +179,28 @@ public abstract class AbstractAppRuleDriver implements AppRuleDriver {

public static final String CTX_JS_PREFIX = "JS_PREFIX";
public static final String CTX_PAGE_PREFIX = "PAGE_PREFIX";
public static final String CTX_PAGE_ONREADY_INTERVAL = "PAGE_ONREADY_INTERVAL";
public static final String CTX_BUBBLE_REQUEST_ID = "BUBBLE_REQUEST_ID";
public static final String CTX_BUBBLE_DATA_ID = "BUBBLE_DATA_ID";
public static final String CTX_BUBBLE_HOME = "BUBBLE_HOME";
public static final String CTX_SITE = "SITE";
public static final String CTX_BUBBLE_SITE_NAME = "BUBBLE_SITE_NAME";
public static final String CTX_BUBBLE_APP_NAME = "BUBBLE_APP_NAME";
public static final String CTX_ICON_JS = "ICON_JS";

private String getPagePrefix(String requestId) { return "__bubble_"+sha256_hex(requestId); }
private String getJsPrefix(String requestId) { return "__bubble_"+sha256_hex(requestId+"_"+getClass().getName()); }
public static final int PAGE_ONREADY_INTERVAL = 50;

private String getPagePrefix(String requestId) { return "__bubble_page_"+sha256_hex(requestId); }
private String getJsPrefix(String requestId) { return "__bubble_js_"+sha256_hex(requestId+"_"+getClass().getName()); }

protected Map<String, Object> getBubbleJsContext(String requestId, Map<String, Object> filterCtx) {
final Map<String, Object> ctx = new HashMap<>();
ctx.put(CTX_PAGE_PREFIX, getPagePrefix(requestId));
ctx.put(CTX_JS_PREFIX, getJsPrefix(requestId));
ctx.put(CTX_PAGE_ONREADY_INTERVAL, PAGE_ONREADY_INTERVAL);
ctx.put(CTX_BUBBLE_REQUEST_ID, requestId);
ctx.put(CTX_BUBBLE_HOME, configuration.getPublicUriBase());
ctx.put(CTX_SITE, getSiteName(matcher));
ctx.put(CTX_BUBBLE_SITE_NAME, getSiteName(matcher));
ctx.put(CTX_BUBBLE_APP_NAME, app.getName());
ctx.put(CTX_BUBBLE_DATA_ID, getDataId(requestId));
return ctx;
}


+ 2
- 1
bubble-server/src/main/java/bubble/rule/AppRuleDriver.java Wyświetl plik

@@ -7,6 +7,7 @@ package bubble.rule;
import bubble.model.account.Account;
import bubble.model.app.AppMatcher;
import bubble.model.app.AppRule;
import bubble.model.app.BubbleApp;
import bubble.model.device.Device;
import bubble.resources.stream.FilterHttpRequest;
import bubble.resources.stream.FilterMatchersRequest;
@@ -30,7 +31,6 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
import static org.cobbzilla.util.daemon.ZillaRuntime.now;
import static org.cobbzilla.util.io.StreamUtil.stream2bytes;
import static org.cobbzilla.util.io.StreamUtil.stream2string;
import static org.cobbzilla.util.security.ShaUtil.sha256_hex;
import static org.cobbzilla.util.string.StringUtil.getPackagePath;

public interface AppRuleDriver {
@@ -73,6 +73,7 @@ public interface AppRuleDriver {

default void init(JsonNode config,
JsonNode userConfig,
BubbleApp app,
AppRule rule,
AppMatcher matcher,
Account account,


+ 3
- 1
bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockRuleDriver.java Wyświetl plik

@@ -8,6 +8,7 @@ import bubble.abp.*;
import bubble.model.account.Account;
import bubble.model.app.AppMatcher;
import bubble.model.app.AppRule;
import bubble.model.app.BubbleApp;
import bubble.model.device.Device;
import bubble.resources.stream.FilterHttpRequest;
import bubble.resources.stream.FilterMatchersRequest;
@@ -68,11 +69,12 @@ public class BubbleBlockRuleDriver extends TrafficAnalyticsRuleDriver implements

@Override public void init(JsonNode config,
JsonNode userConfig,
BubbleApp app,
AppRule rule,
AppMatcher matcher,
Account account,
Device device) {
super.init(config, userConfig, rule, matcher, account, device);
super.init(config, userConfig, app, rule, matcher, account, device);
refreshBlockLists();
}



+ 1
- 1
bubble-server/src/main/java/bubble/service/stream/StandardAppPrimerService.java Wyświetl plik

@@ -137,7 +137,7 @@ public class StandardAppPrimerService implements AppPrimerService {
final Set<String> blockDomains = new HashSet<>();
final Set<String> filterDomains = new HashSet<>();
for (AppMatcher matcher : matchers) {
final AppRuleDriver appRuleDriver = rule.initDriver(driver, matcher, account, device);
final AppRuleDriver appRuleDriver = rule.initDriver(app, driver, matcher, account, device);
final Set<String> blocks = appRuleDriver.getPrimedBlockDomains();
if (empty(blocks)) {
log.debug("_prime: no blockDomains for device/app/rule/matcher: " + device.getName() + "/" + app.getName() + "/" + rule.getName() + "/" + matcher.getName());


+ 10
- 2
bubble-server/src/main/java/bubble/service/stream/StandardRuleEngineService.java Wyświetl plik

@@ -5,10 +5,12 @@
package bubble.service.stream;

import bubble.dao.app.AppRuleDAO;
import bubble.dao.app.BubbleAppDAO;
import bubble.dao.app.RuleDriverDAO;
import bubble.model.account.Account;
import bubble.model.app.AppMatcher;
import bubble.model.app.AppRule;
import bubble.model.app.BubbleApp;
import bubble.model.app.RuleDriver;
import bubble.model.device.Device;
import bubble.resources.stream.FilterHttpRequest;
@@ -75,6 +77,7 @@ public class StandardRuleEngineService implements RuleEngineService {

public static final String HEADER_PASSTHRU = "X-Bubble-Passthru";

@Autowired private BubbleAppDAO appDAO;
@Autowired private AppRuleDAO ruleDAO;
@Autowired private RuleDriverDAO driverDAO;
@Autowired private BubbleConfiguration configuration;
@@ -243,10 +246,15 @@ public class StandardRuleEngineService implements RuleEngineService {
for (AppRuleHarness h : rules) {
final RuleDriver ruleDriver = driverDAO.findByUuid(h.getRule().getDriver());
if (ruleDriver == null) {
log.warn("initRules: driver not found: "+h.getRule().getDriver());
log.warn("initRuleHarnesses: driver not found: "+h.getRule().getDriver());
continue;
}
final AppRuleDriver unwiredDriver = h.getRule().initDriver(ruleDriver, h.getMatcher(), account, device);
final BubbleApp app = appDAO.findByAccountAndId(account.getUuid(), h.getRule().getApp());
if (app == null) {
log.warn("initRuleHarnesses: app not found: "+h.getRule().getApp());
continue;
}
final AppRuleDriver unwiredDriver = h.getRule().initDriver(app, ruleDriver, h.getMatcher(), account, device);
final AppRuleDriver driver = configuration.autowire(unwiredDriver);
h.setRuleDriver(ruleDriver);
h.setDriver(driver);


+ 10
- 3
bubble-server/src/main/resources/bubble/rule/RequestModifierRule_icon.js.hbs Wyświetl plik

@@ -1,7 +1,6 @@

if (typeof {{PAGE_PREFIX}}_icon_status === 'undefined') {
let {{PAGE_PREFIX}}_doc_ready = false;
const {{PAGE_PREFIX}}_interval = 50;

{{PAGE_PREFIX}}_icon_status = [];

@@ -12,7 +11,7 @@ if (typeof {{PAGE_PREFIX}}_icon_status === 'undefined') {
window.clearInterval(intervalId);
callback.call(this);
}
}, {{PAGE_PREFIX}}_interval);
}, {{PAGE_ONREADY_INTERVAL}});
}

{{PAGE_PREFIX}}_onReady(function() {
@@ -28,7 +27,15 @@ if (typeof {{PAGE_PREFIX}}_icon_status === 'undefined') {
document.getElementsByTagName('body')[0].appendChild(bubbleControlDiv);
}
for (let i=0; i<{{PAGE_PREFIX}}_icon_status.length; i++) {
bubbleControlDiv.innerHTML = bubbleControlDiv.innerHTML + {{PAGE_PREFIX}}_icon_status[i].iconHtml;
let br = document.createElement('br');
let link = document.createElement('a');
link.href = '{{{BUBBLE_HOME}}}/app/' + {{PAGE_PREFIX}}_icon_status[i].app + '/' + {{PAGE_PREFIX}}_icon_status[i].link;
let img = document.createElement('img');
img.src = '/__bubble/api/filter/assets/{{BUBBLE_REQUEST_ID}}/' + {{PAGE_PREFIX}}_icon_status[i].app + '/' + {{PAGE_PREFIX}}_icon_status[i].icon + '?raw=true';
img.width = 64;
link.appendChild(img);
bubbleControlDiv.appendChild(br);
bubbleControlDiv.appendChild(link);
}
});
}

+ 4
- 2
bubble-server/src/main/resources/bubble/rule/bblock/BubbleBlockRuleDriver_stats.js.hbs Wyświetl plik

@@ -5,6 +5,8 @@

{{PAGE_PREFIX}}_icon_status.push({
jsPrefix: '{{JS_PREFIX}}',
iconHtml: '<br/><a href="{{{BUBBLE_HOME}}}/app/BubbleBlock/view/last_24_hours"><img width="64" src="/__bubble/api/filter/assets/{{BUBBLE_REQUEST_ID}}/BubbleBlock/icon-gray?raw=true"/></a>'
app: '{{BUBBLE_APP_NAME}}',
link: 'view/last_24_hours',
icon: 'icon-gray'
});
console.log("BubbleBlock pushed icon, {{PAGE_PREFIX}}_icon_status="+JSON.stringify({{PAGE_PREFIX}}_icon_status));
console.log("BubbleBlock pushed icon, {{PAGE_PREFIX}}_icon_status="+JSON.stringify({{PAGE_PREFIX}}_icon_status));

+ 3
- 1
bubble-server/src/main/resources/bubble/rule/social/block/JsUserBlockerRuleDriver.js.hbs Wyświetl plik

@@ -55,6 +55,8 @@ function {{JS_PREFIX}}_block_user (author) {

{{PAGE_PREFIX}}_icon_status.push({
jsPrefix: '{{JS_PREFIX}}',
iconHtml: '<br/><a href="{{{BUBBLE_HOME}}}/app/UserBlocker/site/{{SITE}}/view/blocked_users"><img width="64" src="/__bubble/api/filter/assets/{{BUBBLE_REQUEST_ID}}/UserBlocker/icon?raw=true"/></a>'
app: '{{BUBBLE_APP_NAME}}',
link: 'site/{{BUBBLE_SITE_NAME}}/view/blocked_users',
icon: 'icon'
});
console.log("JsUserBlocker pushed icon, {{PAGE_PREFIX}}_icon_status="+JSON.stringify({{PAGE_PREFIX}}_icon_status));

Ładowanie…
Anuluj
Zapisz