| | |
| | | See the License for the specific language governing permissions and
|
| | | limitations under the License.
|
| | | */
|
| | |
|
| | | package com.gitblit.wicket.ng;
|
| | |
|
| | | import java.text.MessageFormat;
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.apache.wicket.ResourceReference;
|
| | | import org.apache.wicket.markup.html.IHeaderContributor;
|
| | | import org.apache.wicket.markup.html.IHeaderResponse;
|
| | |
|
| | |
| | | * Simple AngularJS data controller which injects scoped objects as static,
|
| | | * embedded JSON within the generated page. This allows use of AngularJS
|
| | | * client-side databinding (magic) with server-generated pages.
|
| | | * |
| | | *
|
| | | * @author James Moger
|
| | | * |
| | | *
|
| | | */
|
| | | public class NgController implements IHeaderContributor {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | | |
| | |
|
| | | final String name;
|
| | | |
| | |
|
| | | final Map<String, Object> variables;
|
| | | |
| | |
|
| | | public NgController(String name) {
|
| | | this.name = name;
|
| | | this.variables = new HashMap<String, Object>();
|
| | | }
|
| | | |
| | |
|
| | | public void addVariable(String name, Object o) {
|
| | | variables.put(name, o);
|
| | | }
|
| | |
| | | @Override
|
| | | public void renderHead(IHeaderResponse response) {
|
| | | // add Google AngularJS reference
|
| | | response.renderJavascriptReference("bootstrap/js/angular.js");
|
| | | response.renderJavascriptReference(new ResourceReference(NgController.class, "angular.js"));
|
| | |
|
| | | Gson gson = new GsonBuilder().create();
|
| | |
|
| | |
| | | line(sb, MessageFormat.format("\t$scope.{0} = {1};", var, json));
|
| | | }
|
| | | line(sb, "}");
|
| | | |
| | |
|
| | | response.renderJavascript(sb.toString(), null);
|
| | | }
|
| | |
|