|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import os |
| 4 | +from glob import glob |
4 | 5 | import typing as t |
5 | 6 |
|
6 | 7 | import importlib_resources |
7 | 8 | from tutor import hooks |
| 9 | +from tutormfe.hooks import PLUGIN_SLOTS |
8 | 10 | from tutor.__about__ import __version_suffix__ |
9 | 11 |
|
10 | 12 | from .__about__ import __version__ |
@@ -102,70 +104,38 @@ def _override_openedx_docker_image( |
102 | 104 | hooks.Filters.CONFIG_OVERRIDES.add_items(list(config["overrides"].items())) |
103 | 105 |
|
104 | 106 |
|
| 107 | +# MFEs that are styled using Indigo |
| 108 | +indigo_styled_mfes = [ |
| 109 | + "learning", |
| 110 | + "learner-dashboard", |
| 111 | + "profile", |
| 112 | + "account", |
| 113 | + "discussions", |
| 114 | +] |
| 115 | + |
105 | 116 | hooks.Filters.ENV_PATCHES.add_items( |
106 | 117 | [ |
107 | | - # MFE will install header version 3.0.x and will include indigo-footer as a |
108 | | - # separate package for use in env.config.jsx |
109 | 118 | ( |
110 | | - "mfe-dockerfile-post-npm-install-learning", |
| 119 | + f"mfe-dockerfile-post-npm-install-{mfe}", |
111 | 120 | """ |
112 | | -RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1' |
113 | | -RUN npm install '@edx/frontend-component-header@npm:@edly-io/indigo-frontend-component-header@^3.1.3' |
| 121 | + |
114 | 122 | RUN npm install @edly-io/indigo-frontend-component-footer@^2.0.0 |
115 | | -
|
116 | | -COPY indigo/env.config.jsx /openedx/app/ |
117 | | -""", |
118 | | - ), |
119 | | - ( |
120 | | - "mfe-dockerfile-post-npm-install-authn", |
121 | | - """ |
122 | | -RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1' |
123 | | -""", |
124 | | - ), |
125 | | - # Tutor-Indigo v2.1 targets the styling updates in discussions and learner-dashboard MFE |
126 | | - # brand-openedx is related to styling updates while others are for header and footer updates |
127 | | - ( |
128 | | - "mfe-dockerfile-post-npm-install-discussions", |
129 | | - """ |
130 | | -RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1' |
131 | 123 | RUN npm install '@edx/frontend-component-header@npm:@edly-io/indigo-frontend-component-header@^3.1.3' |
132 | | -RUN npm install @edly-io/indigo-frontend-component-footer@^2.0.0 |
133 | | -
|
134 | | -COPY indigo/env.config.jsx /openedx/app/ |
135 | | -""", |
136 | | - ), |
137 | | - ( |
138 | | - "mfe-dockerfile-post-npm-install-learner-dashboard", |
139 | | - """ |
140 | 124 | RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1' |
141 | | -RUN npm install @edly-io/indigo-frontend-component-footer@^2.0.0 |
142 | 125 |
|
143 | | -COPY indigo/env.config.jsx /openedx/app/ |
144 | 126 | """, |
145 | | - ), |
146 | | - ( |
147 | | - "mfe-dockerfile-post-npm-install-profile", |
148 | | - """ |
149 | | -RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1' |
150 | | -RUN npm install '@edx/frontend-component-header@npm:@edly-io/indigo-frontend-component-header@^3.1.3' |
151 | | -RUN npm install @edly-io/indigo-frontend-component-footer@^2.0.0 |
152 | | -
|
153 | | -COPY indigo/env.config.jsx /openedx/app/ |
154 | | -""", |
155 | | - ), |
156 | | - ( |
157 | | - "mfe-dockerfile-post-npm-install-account", |
158 | | - """ |
159 | | -RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1' |
160 | | -RUN npm install '@edx/frontend-component-header@npm:@edly-io/indigo-frontend-component-header@^3.1.3' |
161 | | -RUN npm install @edly-io/indigo-frontend-component-footer@^2.0.0 |
162 | | -
|
163 | | -COPY indigo/env.config.jsx /openedx/app/ |
164 | | -""", |
165 | | - ), |
| 127 | + ) |
| 128 | + for mfe in indigo_styled_mfes |
166 | 129 | ] |
167 | 130 | ) |
168 | 131 |
|
| 132 | +hooks.Filters.ENV_PATCHES.add_item( |
| 133 | + ( |
| 134 | + "mfe-dockerfile-post-npm-install-authn", |
| 135 | + "RUN npm install '@edx/brand@npm:@edly-io/indigo-brand-openedx@^2.1.1'", |
| 136 | + ) |
| 137 | +) |
| 138 | + |
169 | 139 | # Include js file in lms main.html, main_django.html, and certificate.html |
170 | 140 |
|
171 | 141 | hooks.Filters.ENV_PATCHES.add_items( |
@@ -204,3 +174,47 @@ def _override_openedx_docker_image( |
204 | 174 | ), |
205 | 175 | ] |
206 | 176 | ) |
| 177 | + |
| 178 | + |
| 179 | +# Apply patches from tutor-indigo |
| 180 | +for path in glob( |
| 181 | + os.path.join( |
| 182 | + str(importlib_resources.files("tutorindigo") / "patches"), |
| 183 | + "*", |
| 184 | + ) |
| 185 | +): |
| 186 | + with open(path, encoding="utf-8") as patch_file: |
| 187 | + hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read())) |
| 188 | + |
| 189 | + |
| 190 | +for mfe in indigo_styled_mfes: |
| 191 | + PLUGIN_SLOTS.add_item( |
| 192 | + ( |
| 193 | + mfe, |
| 194 | + "footer_slot", |
| 195 | + """ |
| 196 | + { |
| 197 | + op: PLUGIN_OPERATIONS.Hide, |
| 198 | + widgetId: 'default_contents', |
| 199 | + }, |
| 200 | + { |
| 201 | + op: PLUGIN_OPERATIONS.Insert, |
| 202 | + widget: { |
| 203 | + id: 'default_contents', |
| 204 | + type: DIRECT_PLUGIN, |
| 205 | + priority: 1, |
| 206 | + RenderWidget: <IndigoFooter />, |
| 207 | + }, |
| 208 | + }, |
| 209 | + { |
| 210 | + op: PLUGIN_OPERATIONS.Insert, |
| 211 | + widget: { |
| 212 | + id: 'read_theme_cookie', |
| 213 | + type: DIRECT_PLUGIN, |
| 214 | + priority: 2, |
| 215 | + RenderWidget: AddDarkTheme, |
| 216 | + }, |
| 217 | + }, |
| 218 | + """, |
| 219 | + ), |
| 220 | + ) |
0 commit comments