Skip to content

Commit

Permalink
add aspect to ribbon
Browse files Browse the repository at this point in the history
  • Loading branch information
mpern committed Mar 4, 2021
1 parent d1ed838 commit 2c841bc
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 31 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
> **Archived on 2020-02-16**\
> I recently switched jobs away from SAP Commerce development
# Environment Ribbons for SAP Commerce
[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/W7W7VS24)

Expand Down Expand Up @@ -30,8 +27,10 @@ If you want to add a ribbon component to your storefront:
(Build callbacks take care of copying the stylesheet where it is needed)
- If deployed in a CCv2 environment, the extension will **auto-detect** the environment (code and type)
- For on-prem environments (or if you want to override the detected values), you can use:
```

```properties
ribbon.environment.code=<environment identifier>
ribbon.environment.aspect=<aspect name, optional>
ribbon.environment.type=<type>
# development, staging, production
```
53 changes: 32 additions & 21 deletions envribbon/.project
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>envribbon</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<name>envribbon</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1614850693495</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@

if (meta.dataset.environment &amp;&amp; meta.dataset.type) {
var container = document.createElement("div");
var environment = meta.dataset.environment

container.id = 'mpern-env-ribbon';
container.classList.add("mpern-env-ribbon");
container.setAttribute("data-environment", meta.dataset.environment);
container.setAttribute("data-type", meta.dataset.type);

if (meta.dataset.aspect) {
environment += "\n(" + meta.dataset.aspect + ")";
}

container.setAttribute("data-environment", environment);

document.body.insertBefore(container, document.body.firstChild);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public void initialize(Component comp) {
EnvironmentMetaData environmentMetaData = environmentMetaDataService.getMetaData();
envRibbon.setClientDataAttribute("environment", environmentMetaData.getCode());
envRibbon.setClientDataAttribute("type", environmentMetaData.getType());
envRibbon.setClientDataAttribute("aspect", environmentMetaData.getAspect());
}
}
4 changes: 4 additions & 0 deletions envribbon/hac/resources/static/js/envribbon.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
container.dataset.environment = env.code;
container.dataset.type = env.type;

if (env.aspect) {
container.dataset.environment += "\n(" + env.aspect + ")";
}

document.body.insertBefore(container, document.body.firstChild);
}
}
Expand Down
6 changes: 6 additions & 0 deletions envribbon/project.properties
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
envribbon.application-context=envribbon-spring.xml

# ribbon.environment.code=
# ribbon.environment.aspect=

# ribbon.environment.type=
# supported types: development, staging, production
1 change: 1 addition & 0 deletions envribbon/resources/envribbon-beans.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<bean class="mpern.sap.commerce.ribbon.EnvironmentMetaData">
<property name="code" type="String"/>
<property name="type" type="String"/>
<property name="aspect" type="String" />
</bean>
</beans>
8 changes: 4 additions & 4 deletions envribbon/resources/envribbon/envribbon.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
z-index: 10000;

font-family: monospace;
font-size: 24px;
font-size: 1rem;
line-height: 1em;
text-transform: uppercase;
white-space: nowrap;
white-space: pre;

overflow: hidden;
position: absolute;
Expand All @@ -23,10 +23,10 @@
.mpern-env-ribbon::before {
content: attr(data-environment);
display: block;
padding: 1em 2em;
padding: 0.5em 0;
font-weight: 800;
text-align: center;
}
.mpern-env-ribbon[data-type=development] { background-color: #a1b56c }
.mpern-env-ribbon[data-type=staging] { background-color: #dc9656 }
.mpern-env-ribbon[data-type=production] { background-color: #ab4642 }
.mpern-env-ribbon[data-type=production] { background-color: #ab4642 }
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ public EnvironmentMetaData getMetaData() {

data.setCode(readEnvironmentFromConfig());
data.setType(readTypeFromConfig());
data.setAspect(readAspectFromEnv());

return data;
}

private String readAspectFromEnv() {
String aspect = configurationService.getConfiguration().getString("ribbon.environment.aspect", "");
if (aspect.isEmpty()) {
//env var is available in ccv2
aspect = System.getenv("ASPECT_NAME");
}
return aspect;
}

private String readEnvironmentFromConfig() {
String env = configurationService.getConfiguration().getString("ribbon.environment.code", "");
if (env.isEmpty()) {
Expand Down
12 changes: 11 additions & 1 deletion envribbonaddon/.project
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@
<arguments>
</arguments>
</buildCommand>

</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1614850693506</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
(function () {
var environment = '<c:out value="${env.code}" />',
type = '<c:out value="${env.type}" />',
aspect = '<c:out value="${env.aspect}" />',
container = document.createElement("div");
if (environment && type) {
Expand All @@ -14,6 +15,10 @@
container.dataset.environment = environment;
container.dataset.type = type;
if (aspect) {
container.dataset.environment += "\n(" + env.aspect + ")";
}
document.body.insertBefore(container, document.body.firstChild);
}
})();
Expand Down

0 comments on commit 2c841bc

Please sign in to comment.